指点一下回调函数(20分)

  • 主题发起人 主题发起人 chuliheng
  • 开始时间 开始时间
C

chuliheng

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, Unit2, Unit3, StdCtrls, Buttons;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; BitBtn1: TBitBtn;<br>&nbsp; &nbsp; procedure BitBtn1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; Frm2 : TForm2;<br>&nbsp; &nbsp; procedure CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr);<br>var<br>&nbsp; I : Integer;<br>begin<br>&nbsp; For I :=0 to length(APeijInfoArr) -1 do<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('aaaa');<br>&nbsp; end;<br>&nbsp; FreeAndNil(frm2);<br>end;<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br>&nbsp; APeijInfoArr : TPeijInfoArr;<br>begin<br>&nbsp; Frm2 := TForm2.Create(Self);<br>&nbsp; Try<br>&nbsp; &nbsp; Frm2.CallBackAdd := CallBackXiaoShouPeijInfo; &nbsp;//报错位置<br>&nbsp; &nbsp; frm2.Show;<br>&nbsp; except<br>&nbsp; end;<br>end;<br><br>end.<br>========================================================================<br>unit Unit2;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, Unit3, StdCtrls;<br><br>type<br>&nbsp; TCallBackAdd = procedure(const ApeijInfoArr : TPeijInfoArr) of object;<br>&nbsp; TForm2 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br><br>&nbsp; &nbsp; PeijInfo : TPeijInfo;<br><br>&nbsp; &nbsp; procedure AddPeijInfo(const kehu_no : String);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; CallBackAdd: TCallBackAdd;<br>&nbsp; &nbsp; PeijInfoArr : TPeijInfoArr;<br>&nbsp; end;<br><br>//var<br>&nbsp; //Form2: TForm2;<br><br>implementation<br><br>{$R *.dfm}<br><br><br>{ TForm2 }<br><br>procedure TForm2.AddPeijInfo(const kehu_no: String);<br>var<br>&nbsp; I : Integer;<br>begin<br>&nbsp; For i :=0 to 100 do<br>&nbsp; begin<br>&nbsp; &nbsp; SetLength(PeijInfoArr,length(PeijInfoArr)+1);<br>&nbsp; &nbsp; PeijInfoArr.peij_no := '001';<br>&nbsp; &nbsp; PeijInfoArr.peij_mc := '001';<br>&nbsp; &nbsp; PeijInfoArr.peij_th := '001';<br>&nbsp; &nbsp; PeijInfoArr.peij_qt := '001';<br>&nbsp; &nbsp; PeijInfoArr.cangk_dm := '01';<br>&nbsp; end;<br>&nbsp; if Assigned(CallBackAdd) then CallBackAdd(PeijInfoArr) ;<br>end;<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>begin<br>&nbsp; AddPeijInfo('kehu_no');<br>end;<br><br>end.<br>=================================================================<br>unit Unit3;<br><br>interface<br>Type<br>&nbsp; TPeijInfo = Record<br>&nbsp; &nbsp; peij_no : String;<br>&nbsp; &nbsp; peij_mc : String;<br>&nbsp; &nbsp; peij_th : String;<br>&nbsp; &nbsp; Peij_qt : String;<br>&nbsp; &nbsp; Cangk_dm: String;<br>&nbsp; end;<br>TPeijInfoArr = Array of TpeijInfo;<br><br>implementation<br><br>end.<br><br>请高人指点一下回调函数的应用,在注明报错位置的地方报错,不知为什么,请高手指点
 
procedure TForm1.CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr);<br>这里改成:<br>procedure CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr);<br><br>Frm2.CallBackAdd := CallBackXiaoShouPeijInfo; &nbsp;//报错位置<br>这里改成:<br>Frm2.CallBackAdd := @CallBackXiaoShouPeijInfo; &nbsp;//报错位置<br><br>未测试。
 
To:lanyaoshi<br>&nbsp; 还是编译不过去!<br><br>继续等待中。。。。。。
 
问题已解决,<br>procedure CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr); 修改成<br>procedure CallBackXiaoShouPeijInfo(Const APeijInfoArr : TPeijInfoArr);<br><br>希望大家不要跟我犯一样的错误<br>还是很感谢 lanyaoshi
 

Similar threads

I
回复
0
查看
551
import
I
I
回复
0
查看
699
import
I
I
回复
0
查看
519
import
I
后退
顶部