delphi의 함수 바늘 리셋 함수

1286 단어
다음 코드는 테스트 코드일 뿐입니다:delphi XE7 UP1
interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    edt1: TEdit;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
  end;

  TMethod = procedure(v:string);
var
  Form1: TForm1;
  FList: TList;

implementation

{$R *.dfm}

procedure p1(v:string);
begin
  ShowMessage('p1'+v);
end;

procedure p2(v:string);
begin
  ShowMessage('p2'+v);
end;



procedure callt(my:TMethod;v:string);
begin
  my(v);
end;



procedure TForm1.btn1Click(Sender: TObject);
var
  v_s:string;
begin
  v_s:= edt1.Text;
  callt(FList.Items[StrToInt(v_s)],v_s);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   FList := TList.Create;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  FList.Add(@p1);
  FList.Add(@p2);
  edt1.Clear;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FList);
end;

end.

좋은 웹페이지 즐겨찾기