我的代码如下
.
type
TDATA = record
MissionName :string;
sTime :string;
Completed :string;
Mission :string;
MissionCnt :string;
end;
......var
DATA:^TDATA;
begin
New(DATA);
DATA^.MissionName:=edtMissionName.Text; //,编译没问题,运行到这里就出错
DATA^.Completed:='0';
DATA^.sTime:=DateToStr(DateTimePicker1.Date) + ' ' + edtTime.Text;
DATA^.Mission:=mmoMission.Text;
DATA^.MissionCnt:=MmoCnt.Text; SendMessage(FrmMission.Handle,MyMessage,0,lparam(DATA));
.
type
TDATA = record
MissionName :string;
sTime :string;
Completed :string;
Mission :string;
MissionCnt :string;
end;
......var
DATA:^TDATA;
begin
New(DATA);
DATA^.MissionName:=edtMissionName.Text; //,编译没问题,运行到这里就出错
DATA^.Completed:='0';
DATA^.sTime:=DateToStr(DateTimePicker1.Date) + ' ' + edtTime.Text;
DATA^.Mission:=mmoMission.Text;
DATA^.MissionCnt:=MmoCnt.Text; SendMessage(FrmMission.Handle,MyMessage,0,lparam(DATA));
DATA后面的尖括号去掉:)
type
myData=^TData;
TDATA = record
MissionName :string;
sTime :string;
Completed :string;
Mission :string;
MissionCnt :string;
end;调用:
var ss:myData;
begin
new(ss);
ss.MissionName:='test';
dispose(ss);
end;
type
myData=^TData;
TDATA = record
MissionName :string;
sTime :string;
Completed :string;
Mission :string;
MissionCnt :string;
end;
var
aDATA:myData;
begin
New(aDATA);
aDATA.MissionName:=edtMissionName.Text;
aDATA.Completed:='0';
aDATA.sTime:=DateToStr(DateTimePicker1.Date) + ' ' + edtTime.Text;
aDATA.Mission:=mmoMission.Text;
aDATA.MissionCnt:=MmoCnt.Text; SendMessage(FrmMission.Handle,MyMessage,0,lparam(aDATA));还是一样
var
Handle : THandle;
begin
Handle := FindWindow(nil, PChar(Edit1.Text));
if Handle <> 0 then
begin
GetWindowRect(Handle, pRect);
EnumChildWindows(Handle, @EnumChildWindowProc, 0);
end;
end;
function EnumChildWindowProc(hWnd : Integer; lParam : Integer): Boolean; stdcall;
var
cName : array[0..254] of Char;
wText : array[0..254] of Char;
cRect : TRect;
begin
GetClassName(hWnd, cName, 255);
GetWindowText(hWnd, wText, 255);
GetWindowRect(hWnd, cRect);
Result := True;
end;
PSelRecord=^TSelRecord;
TSelRecord=packed record
gh:string;
xm:string;
lzrq:TDateTime;
tzrq:TDateTime;
end; lst:array [0..1000] of PSelRecord;
lst_Count:Integer;
aPak:PSelRecord;New(aPak);
aPak^.gh:=Trim(VarToStr(Values[2]));
aPak^.xm:=Trim(VarToStr(Values[3])); aPak^.lzrq:=StrToDate(IfThen((VarToStr(Values[14])<>'')and(StrToDate(VarToStr(Values[14]))>=qry_bb.fieldbyname('dt').AsDateTime),
VarToStr(Values[14]),
VarToStr(Values[13])
));
aPak^.tzrq:=apak^.lzrq;
我的问题不是这个。这个已经解决sendmessage应该如何传参
请看这个单元的SendData方法,界面很简单:就是发送0:字符串;1:Image;2:Record;消息的Handle有所变化
unit SenderMain;{How to send information (String, Image, Record) between two Delphi applicationshttp://delphi.about.com/od/windowsshellapi/a/wm_copydata.htmLearn how to send the WM_CopyData message between two Delphi
applications to exchange information and make two applications
communicate. The accompanying source code demonstrates how to
send a string, record (complex data type) and even graphics
to another application.
~Zarko Gajic
About Delphi Programming
http://delphi.about.com
}interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type(*
Declared in Windows.pas TCopyDataStruct = packed record
dwData: DWORD; //up to 32 bits of data to be passed to the receiving application
cbData: DWORD; //the size, in bytes, of the data pointed to by the lpData member
lpData: Pointer; //Points to data to be passed to the receiving application. This member can be nil.
end;*)
TCopyDataType = (cdtString = 0, cdtImage = 1, cdtRecord = 2); TSampleRecord = packed record
s : string[50];
i : integer;
d : TDateTime;
end;
TSenderMainForm = class(TForm)
SendDataButton: TButton;
rgCopyOptions: TRadioGroup;
procedure SendDataButtonClick(Sender: TObject);
private
procedure SendData(copyDataStruct : TCopyDataStruct); procedure SendString();
procedure SendImage();
procedure SendRecord();
public
{ Public declarations }
end;var
SenderMainForm: TSenderMainForm;implementation{$R *.dfm}procedure TSenderMainForm.SendData(
copyDataStruct: TCopyDataStruct);
var
receiverHandle : THandle;
res : integer;
begin
receiverHandle := FindWindow(PChar('TReceiverMainForm'),PChar('ReceiverMainForm'));
if receiverHandle = 0 then
begin
ShowMessage('CopyData Receiver NOT found!');
Exit;
end; res := SendMessage(receiverHandle, WM_COPYDATA, Integer(Handle), Integer(@copyDataStruct)); if res > 0 then ShowMessage(Format('Receiver has %d lines in Memo!',[res]));
end;procedure TSenderMainForm.SendDataButtonClick(Sender: TObject);
begin
if rgCopyOptions.ItemIndex = -1 then
begin
ShowMessage('Nothing selected!');
Exit;
end; case rgCopyOptions.ItemIndex of
0 : SendString;
1 : SendImage;
2 : SendRecord;
end;
end;procedure TSenderMainForm.SendImage();
var
ms : TMemoryStream;
bmp : TBitmap;
copyDataStruct : TCopyDataStruct;
begin
ms := TMemoryStream.Create;
try
bmp := self.GetFormImage;
try
bmp.SaveToStream(ms);
finally
bmp.FreeImage;
end;
copyDataStruct.dwData := Integer(cdtImage); //use it to identify the message contents
copyDataStruct.cbData := ms.Size;
copyDataStruct.lpData := ms.Memory; SendData(copyDataStruct);
finally
ms.Free;
end;
end;procedure TSenderMainForm.SendRecord();
var
sampleRecord : TSampleRecord;
copyDataStruct : TCopyDataStruct;
begin
sampleRecord.s := 'Hello Receiver';
sampleRecord.i := 1973;
sampleRecord.d := Now; copyDataStruct.dwData := Integer(cdtRecord); //use it to identify the message contents
copyDataStruct.cbData := SizeOf(sampleRecord);
copyDataStruct.lpData := @sampleRecord; SendData(copyDataStruct);end;procedure TSenderMainForm.SendString();
var
stringToSend : string;
copyDataStruct : TCopyDataStruct;
begin
stringToSend := 'About Delphi Programming'; copyDataStruct.dwData := Integer(cdtString); //use it to identify the message contents
copyDataStruct.cbData := 1 + Length(stringToSend);
copyDataStruct.lpData := PChar(stringToSend); SendData(copyDataStruct);
end;end.
SendMessage(receiverHandle, WM_COPYDATA, Integer(Handle), Integer(@copyDataStruct));
Integer(@copyDataStruct))和我的Integer(aDATA)有什么区别吗?aDATA是PDATA指针类型
还是报错。