天
天道酬勤
Unregistered / Unconfirmed
GUEST, unregistred user!
我利用wm_copydata在两个窗体之间传递字符串可以。<br>传递字定义的纪录时,老显示乱码?<br>unit1 code:<br>//传递字符<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> ds:Tcopydatastruct;<br>begin<br> ds.cbData:=length(Trim(Self.Edit1.Text))+1;<br> GetMem (ds.lpData, ds.cbData );<br> StrCopy(ds.lpData,PChar(Edit1.Text));<br> try<br> form2:=Tform2.Create(nil);<br> SendMessage(form2.Handle,wm_copydata,self.Handle,Cardinal(@ds));<br> Form2.ShowModal;<br> finally<br> Form2.Free;<br> Freemem(ds.lpdata);<br> end;<br>end;<br><br>//发送记录<br>procedure TForm1.Button2Click(Sender: TObject);<br>type<br> Tstudentinfo=packed record<br> Lname:string[10];<br> Lsex:String[2];<br>end;<br>var<br> ds:Tcopydatastruct;<br>begin<br> ds.cbData:=sizeof(Stuinfo);<br> Getmem(ds.lpData ,ds.cbData);<br> try<br> form2:=Tform2.Create(nil);<br> SendMessage(form2.Handle,wm_copydata,self.Handle,Cardinal(@ds));<br> Form2.ShowModal;<br> finally<br> Form2.Free;<br> Freemem(ds.lpdata);<br> end;<br>end;<br>unit2 code;<br>procedure TForm2.GetData(var Msg: Twmcopydata);<br>begin<br> label1.Caption:=StrPas(Msg.CopyDataStruct^.lpData); 显示字符<br> 记录怎样显示出来?<br>end;<br><br>