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.
  • 相关阅读:
    Metadata, reflection and attribute
    [Tip VS] One Reason Causes VS IDE Slow To Work
    [转载]开源界的5大开源许可协议详解
    [Cursor Bitmap]Programatically Create Bitmap For Cursor
    对UML多了很多理解
    关于Task Breakdown / Plan & Project Prototyping
    第11章 界面设计模式
    第4章 O/R Mapping的一般做法
    第3章 数据和对象
    第8章 事务处理
  • 原文地址:https://www.cnblogs.com/rogge7/p/6418754.html
Copyright © 2011-2022 走看看