我在数据库里有一张表t_procedure:
create table t_procedure
(
   CustNo  varchar(50),    --客户代码
   ProgramName varchar(40) --procedure 名
)insert into t_procedure values('001','procedure1')
insert into t_procedure values('002','procedure2')
insert into t_procedure values('003','procedure3')在界面上有一个edit1,button1,当用户在edit1输入了001后,按button1,要执行的操作是:
1.先到数据库里取出 'procedure1'
2.执行procedure1这个过程(procedure1在代码里是有定义了)procedure procedur1;
begin
  showmessage('1');
end;
procedure procedur2;
begin
  showmessage('2');
end;procedure procedur3;
begin
  showmessage('3');
end;procedure TForm1.button1Click(Sender: TObject);
begin
  adoq_print.Close;
  adoq_print.Parameters.ParamByName('CustNo').Value := edit1.Text;
  adoq_print.Open;
  ???????????????????????????
  ??????????????????????????? (请问这边的代码要怎么写?)
end;

解决方案 »

  1.   

    type
      TMyProcedure = procedure;var
      p :TMyProcedure ;
    begin
      p := MethodAddress('procedure1');  //这儿你可以从数据库中取出
      if Assigned(p) then
        p;
      

  2.   

    如果是published类型的,也可以直接通过名称调用。
      

  3.   

    to windindance(风舞轻扬·白首为功名):我有按你说的那样去写了,
    procedure TForm1.BB_printClick(Sender: TObject);
    type
      TMyProcedure = procedure;
    var
      p :TMyProcedure ;
      a :string;
    begin
      adoq_print.Close;
      adoq_print.Parameters.ParamByName('CustNo').Value := Edit1.Text;
      adoq_print.Parameters.ParamByName('LabelType').Value := ComboBox4.Text;
      adoq_print.Open;
      a := adoq_print.FieldByName('ProgramName').AsString;
      p :=  MethodAddress(adoq_print.FieldByName('ProgramName').AsString);
      if Assigned(p) then
      p;end;
    但不知道为什么还老是报错:
    Project Print.exe raised exception class EAccessViolation with message 'Access violation at address 0044B095 in module print.exe'.Read of address 868C0035'.Process stopped.Use step or Run to contiue.
    请再帮忙看看
    谢谢各位了!
      

  4.   

    你跟踪一下adoq_print.FieldByName('ProgramName').AsString 的值是什么?
      

  5.   

    如果你的procedure1是定义在类里面的,那个类型定义应该写成这个样子:
    type TMyProcedure=Procedure of object;
      

  6.   

    to :windindance(风舞轻扬·白首为功名):
    我跟踪了adoq_print.FieldByName('ProgramName').AsString 的值,是“procedure1”这个值,你说会不会跟procedure1定义在哪里有关系呢?我这个procedure1是定义在TFrom1里,你说跟这个有关系吗?
    能不能留个MSN给我,我好跟您直接沟通,我的MSN是[email protected]。 谢谢
    to :wjowner(Jerry.W):
    我有改成你说的,但就是编译过不了啊!
    请各位再帮忙看看了。
      

  7.   

    >>procedure1是定义在TFrom1里
    应该是在public或published部分。
      

  8.   

    to :windindance(风舞轻扬·白首为功名):
    还是不行啊,能不能把你的EMAIL给我,我把程序发给你,这样看起来比较方便
      

  9.   

    谢谢windindance(风舞轻扬·白首为功名),结贴!
      

  10.   

    MethodAddress is used internally by the streaming system. When an event property is read from a stream, MethodAddress converts a method name, specified by Name, to a pointer containing the method address. There should be no need to call MethodAddress directly.If Name does not specify a published method for the object, MethodAddress returns nil (Delphi) or NULL (C++).
    Procedure必须放在Published声明部分, 否则不能执行