C
chuliheng
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Unit2, Unit3, StdCtrls, Buttons;<br><br>type<br> TForm1 = class(TForm)<br> BitBtn1: TBitBtn;<br> procedure BitBtn1Click(Sender: TObject);<br> private<br> { Private declarations }<br> Frm2 : TForm2;<br> procedure CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr);<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.CallBackXiaoShouPeijInfo(APeijInfoArr : TPeijInfoArr);<br>var<br> I : Integer;<br>begin<br> For I :=0 to length(APeijInfoArr) -1 do<br> begin<br> ShowMessage('aaaa');<br> end;<br> FreeAndNil(frm2);<br>end;<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br> APeijInfoArr : TPeijInfoArr;<br>begin<br> Frm2 := TForm2.Create(Self);<br> Try<br> Frm2.CallBackAdd := CallBackXiaoShouPeijInfo; //报错位置<br> frm2.Show;<br> except<br> end;<br>end;<br><br>end.<br>========================================================================<br>unit Unit2;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Unit3, StdCtrls;<br><br>type<br> TCallBackAdd = procedure(const ApeijInfoArr : TPeijInfoArr) of object;<br> TForm2 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br><br> PeijInfo : TPeijInfo;<br><br> procedure AddPeijInfo(const kehu_no : String);<br> public<br> { Public declarations }<br> CallBackAdd: TCallBackAdd;<br> PeijInfoArr : TPeijInfoArr;<br> end;<br><br>//var<br> //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> I : Integer;<br>begin<br> For i :=0 to 100 do<br> begin<br> SetLength(PeijInfoArr,length(PeijInfoArr)+1);<br> PeijInfoArr.peij_no := '001';<br> PeijInfoArr.peij_mc := '001';<br> PeijInfoArr.peij_th := '001';<br> PeijInfoArr.peij_qt := '001';<br> PeijInfoArr.cangk_dm := '01';<br> end;<br> if Assigned(CallBackAdd) then CallBackAdd(PeijInfoArr) ;<br>end;<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>begin<br> AddPeijInfo('kehu_no');<br>end;<br><br>end.<br>=================================================================<br>unit Unit3;<br><br>interface<br>Type<br> TPeijInfo = Record<br> peij_no : String;<br> peij_mc : String;<br> peij_th : String;<br> Peij_qt : String;<br> Cangk_dm: String;<br> end;<br>TPeijInfoArr = Array of TpeijInfo;<br><br>implementation<br><br>end.<br><br>请高人指点一下回调函数的应用,在注明报错位置的地方报错,不知为什么,请高手指点