我想要完成如下的功能:
写一全个过程
doprocedure(procedurename:string)
该过程能执行procedurename所指的过程。
不知该如何去写。

解决方案 »

  1.   

    doprocedure(procedurename: T***pro);
      

  2.   

    this has an example:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;type
      Taa = procedure;var
      Form1: TForm1;
        s : string;procedure aa;
    procedure bb(proc : Taa);implementation{$R *.DFM}procedure aa;
    begin
      s := 'aa';
    end;
    procedure bb(proc : Taa);
    begin
      proc;
      showMessage(s);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      bb(aa);
    end;end.
      

  3.   

    if you want to use string,You can use if    :P
    if str='aa' then aa
    else str='procedur name' then dosomethinga boring way   :P
      

  4.   

    调用DLL里的过程,好像就是用字符串传递过程名的.
    若不是,....好像只好建立映射表了!
    什么程序非得这么做啊,用过程型变量不是挺好吗?
      

  5.   

    我把要传递的过程写在FORM1的方法中去了,在网上查到的!
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
      published
        procedure Test(const str: string);
        { Public declarations }
      end;
      TCustomProc = procedure(const P: string) of object;
    var
      Form1: TForm1;
    implementation{$R *.DFM}procedure TForm1.Test(const str: string);
    begin
      ShowMessage(str);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      proc: TCustomProc;
    begin
      @proc := MethodAddress('Test');
      if assigned(proc) then
        proc('fjgkldfjgjdfj');
    end;end.