zoukankan      html  css  js  c++  java
  • Delphi 接口统一方法

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
    type
    IDemo=interface
    function A(i:Integer):Integer;
    end;
    
    type
    TDemo=class(TInterfacedObject,IDEmo)
    public
    function A(i:Integer):Integer;
    end;
    
    type
    TDemob=class(TInterfacedObject,IDEmo)
    public
    function A(i:Integer):Integer;
    end;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    { TDemo }
    
    function TDemo.A(i: Integer): Integer;
    begin
     ShowMessage('TDemo _'+inttostr(i));
    end;
    
    { TDemob }
    
    function TDemob.A(i: Integer): Integer;
    begin
     ShowMessage('TDemob _'+inttostr(i));
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
    Demob:TDemob;
    Demo:TDemo;
    vIDemo:IDemo;
    begin
     Demo:=TDemo.Create;
     Demob:=TDemob.Create;
    
    
     vIDemo:=IDemo(Demo);
     vIDemo.A(1);
    
    
     vIDemo:=IDemo(Demob);
     vIDemo.A(2);
    
    end;
    
    end.

  • 相关阅读:
    sh_04_第1个函数改造
    sh_03_第1个函数
    sh_02_快速体验
    sh_01_九九乘法表
    11_测试模块
    sh_12_转义字符
    sh_11_九九乘法表
    sh_10_嵌套打印小星星
    Mariadb/Redis数据库
    部署django项目
  • 原文地址:https://www.cnblogs.com/studycode/p/10115754.html
Copyright © 2011-2022 走看看