zoukankan      html  css  js  c++  java
  • D- 泛型练习 ,继承,方法

    unit Unit3;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.Generics.Collections;
    
    type
      TForm3 = class(TForm)
        btn1: TButton;
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      THttpResult<T: TStrings, constructor> = class   //限定T 为某个类型,
      private
        fIsSucc: Boolean;
        fData: T;
        fMsg: string;
        fUrl: string;
        fParamStr: string;
      public
      end;
      ThttpResultA =class(THttpResult<TStrings>)
      end;
      ThttpResults =class(THttpResult<TStringList>)
      end;
      A<T> =class
      end;
      AA<T> =class(A<T>) //AA=class(A<T>) 这样写会提示说为定义T
      end;
      B=class(A<ThttpResultA>) //B=class(A<int>)  这里会错误, B<T>=class(A<int>)这样不错
      end;
      C<B>=class(A<ThttpResultA>) //这里的B并不是B类,而是一个没有任何意义的 占位符
      end;
      D<T>=class(A<ThttpResultA>) //这里的B并不是B类,而是一个没有任何意义的 占位符
      private
        fIsSucc :Boolean;
      public
        function QueryData<B>(url:string):string;
        function QueryData2<T>(url:string):string; //QueryData<T>(url:string):string; 这样会被认为和上一个函数相同
      end;
      TGQlist<T> = class(TList<T>)  //包含System.Generics.Collections,   TGQlist= class(TList<T>) 这样写是错误的
      end;
    var
      Form3: TForm3;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm3.btn1Click(Sender: TObject);
    var
      temp :TStringList;
      temp2 :A<string>;   //可以这么用法。
    begin
      temp2 := A<string>.Create;  //创建类
    end;
    
    { D<T> }
    
    function D<T>.QueryData<B>(url: string): string;
    begin
      //
    end;
    
    function D<T>.QueryData2<T>(url: string): string;
    begin
    
    end;
    
    end.
  • 相关阅读:
    How to extract msu/msp/msi/exe files from the command line
    Windbg and resources leaks in .NET applications 资源汇总
    [c# 20问] 3.String和string的区别
    [c# 20问] 2.如何转换XML文件
    [c# 20问] 1. 何时使用class与struct
    安装配置BITS上传服务
    The J-Link hardware debugging Eclipse plug-in
    swift material
    SCLButton
    ChatCell
  • 原文地址:https://www.cnblogs.com/rogge7/p/6418754.html
Copyright © 2011-2022 走看看