首页 > 代码库 > D- 泛型练习 ,继承,方法

D- 泛型练习 ,继承,方法

unit Unit3;interfaceuses  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;beginend;end.

 

D- 泛型练习 ,继承,方法