比如我在Form上放了一个Edit,在里面输入一个函数名及其参数,这个函数是程序里已经有的,
这时那我怎么才能调用到这个函数啊?(怎样在程序执行时根据函数名动态找到它的地址?)

解决方案 »

  1.   

    只能通过IFPS这类的PascalScript解释库才能用的
    上Google去找了
      

  2.   

    调用自己程序中的函数,如果函数不多,匹配下还是可以吧/if Edit.Text ='MyFunctionName1' then
       MyFunctionName(p1,p2)
    else if Edit.Text ='MyFunctionName2' then
      MyFunctionName2(P1,P2)
    else ....
      

  3.   

    如果这些函数位于published域,则处理很方便。比如:
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      //……
        published
         procedure Fun(X: Integer);
      end;  TFun = procedure (X: Integer);
    procedure TForm1.Button1Click(Sender: TObject);
    var
      X: string;
      M: Pointer;
      F: TFun;
    begin
      X := Edit1.Text;
      M := MethodAddress(X);
      if M <> nil then
      begin
        @F := M;
        F(1);
      end;
    end;procedure TForm1.Fun(X: Integer);
    begin
      ShowMessage(IntToStr(X));
    end;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  4.   

    嘿嘿~~不一定要用虚拟机或者解释器之类的~~~~试试我的LexLib吧~
    www.yixel.com  带有例子的,用LexLib你也可以自己封装一个简化函数:Run('MessageBox','0,"Hello world","Caption",0');
      

  5.   

    感谢各位。
    firef(火狐) 的方法可以用,刚开始我就是这样用的,不过函数太多,写的太累。
    IFPS和LexLib都下到了,研究中。
    现在用 lxpbuaa(桂枝香在故国晚秋) 的办法,把那些函数包装到了一个类里。