问题一
procedure TForm1.AllOver(Mypro:tprocedure);
var
  i:integer;
begin
  for i:=0 to 100 do
    begin
      if mypro<>nil then mypro   
      //执行if mypro<>nil 时出错,提示类型不匹配,请问如何解决?。
    end;
end;procedure TForm1.showaaaaa;
begin
  showmessage('aaaaaa')
end;
procedure TForm1.button1Click(Sender: TObject);
begin
    Form1.AllOver(Form1.showaaaaa);或Form1.AllOver(nil);
end;问题二
procedure TForm1.AllOver(Mypro:tprocedure);
var
  i:integer;
begin
  for i:=0 to 100 do
    begin
      mypro   
    end;
end;procedure TForm1.showaaaaa(Mystr);
begin
  showmessage(Mystr)
end;
procedure TForm1.button1Click(Sender: TObject);
begin
    Form1.AllOver(Form1.showaaaaa('aaaaaaaa'));
    //当Form1.showaaaaa是无参数的过程时能正常执行,但当Form1.showaaaaa是带有参数的过程时,就编译通不过。
    //请问如何解决?
end;

解决方案 »

  1.   

    Assigned(mypro)
    procedure TForm1.button1Click(Sender: TObject); 
    begin 
        Form1.AllOver(Form1.showaaaaa('aaaaaaaa')); 
        //当Form1.showaaaaa是无参数的过程时能正常执行,但当Form1.showaaaaa是带有参数的过程时,就编译通不过。你定义的是 tprocedure类型
      

  2.   

    有参数的话,
    procedure TForm1.AllOver(Mypro:tprocedure); 
    改变tprocedure类型procedure TForm1.AllOver(Mypro:tprocedure); 改成
    procedure TForm1.AllOver(Mypro:tprocedure;A, B,C: 参数);
    调用时加参数
    mypro调用 mypr0(参数,参数,参数)
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      tp=procedure(Sender: TObject;s:string);
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure AllOver(Mypro:tp;s:string);
        procedure showaaaaa(s:string);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.AllOver(Mypro:tp;s:string);
    var
      i:integer;
    begin
      for i:=0 to 5 do
        begin
          mypro(self,s);
        end;
    end;procedure TForm1.showaaaaa(s:string);
    begin
      showmessage(s);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      a:tp;
    begin
      @a:[email protected];
      AllOver(a,'aaa');
    end;end.
      

  4.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      tprocedure = procedure of object;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        procedure AllOver(Mypro: tprocedure);
        procedure showaaaaa;
        { Public declarations }
      end;var
      Form1: TForm1;
      tp: tprocedure;implementation{$R *.dfm}procedure TForm1.AllOver(Mypro: tprocedure);
    var
      i:integer;
    begin
      for i:=0 to 100 do
        begin
          if @mypro <> nil then mypro;
        end;
    end;procedure TForm1.showaaaaa;
    begin
      showmessage('aaaaaa');
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      tp:= Form1.showaaaaa;
      Form1.AllOver(tp);
    end;end.
      

  5.   

    SuperTitan001,你的这种解决方法,只能解决非常当前的这个单一问题,但没有通用性
    我之所以要传过程给AllOver()的原因是想将AllOver()这个过程通用化,通过调用过程指定执行AllOver时要执行的另外一个过程。
    而你这样写的话,
    procedure TForm1.AllOver(Mypro:tp;s:string); 
    var 
      i:integer; 
    begin 
      for i:=0 to 5 do 
        begin 
          mypro(self,s); 
        end; 
    end; 
    mypro  就一定要参数数量一致,类型一致,失去了通用性。。继续求高人能解决我的问题。。
      

  6.   


    想想动态加载DLL的用法吧,其实也差不多