Re: WM_COPYDATA
- From: jimbo@xxxxxxxxxx
- Date: Sun, 09 Sep 2007 01:45:37 -0700
On Sep 7, 12:09 pm, "Maarten Wiltink" <maar...@xxxxxxxxxxxxxxxxxx>
wrote:
<ji...@xxxxxxxxxx> wrote in message
news:1189139876.636916.80920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I would like to send an array of strings or a stringlist from one app
to another. I'm using Zarko Gajic's WM_COPYDATA example.
http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htm?rd=1
How would I adapt this code to send a TStringList or array of strings
declared in Sender app to Receiver app. How do I handle it? types
typecasting access etc. TIA
For a stringlist, send its Text property. That's all the lines
concatenated together, with end-of-line sequences (CR LF) to
separate them. On the receiving end, assign the text to the Text
property of the receiving TStrings object and it will split it
into lines again.
// replied from my pc but didn't see it. Hope it's not posted twice
Cheers Martin. As always you're a Prince. The stringlist test is below
for
anyone interested. But there is more :>)
///////////// Sender app
type TForm1 .....
Public
mypiclist : TStringList;
procedure TForm1.FormCreate(Sender: TObject);
begin
mypiclist := tstringlist.Create;
mypiclist.Add('string 1');
mypiclist.Add('string 2');
end;
procedure TForm1.SendString();
var
copyDataStruct : TCopyDataStruct;
begin
copyDataStruct.dwData := Integer(cdtString); //use it to identify
the
message contents
copyDataStruct.cbData := 1 + Length(mypiclist.text);
copyDataStruct.lpData := PChar(mypiclist.Text);
SendData(copyDataStruct);
end;
///////////////// Receiver app
procedure TReceiverMainForm.HandleCopyDataString(
copyDataStruct: PCopyDataStruct);
var
list : TStringList;
begin
list := tstringlist.Create;
try
list.Text := PChar(copyDataStruct.lpData);
// do what you want
finally list.free
end;
end;
For an array of strings, you can do the same thing, only you have to
write the code yourself.
Actually, I have a stringlist with objects. I feared to go into detail
in
the op.
Type
TPictureObj = Class(TObject)
Amount : Integer;
Selected : Boolean;
PicPath: String;
TmbPath: String;
End;
For the module I'm writing (receiver app) I only need the path of
selected
objects and I can pull them and assign them to a temporary stringlist
but
will the code run synch? Will the receiver process the data before
the
sender frees it?
not tested
procedure TForm1.SendString();
var
var mylist : tstringlist;
copyDataStruct : TCopyDataStruct;
begin
mylist := tstringlist.create;
try
// loop through mypiclist, if selected add path to mylist
copyDataStruct.dwData := Integer(cdtString); //use it to identify
the
message contents
copyDataStruct.cbData := 1 + Length(mypiclist.text);
copyDataStruct.lpData := PChar(mypiclist.Text);
SendData(copyDataStruct);
finally mylist.free;
end;
end;
How would I cast/send mypiclist in order to receive and process the
objects
if need be?
Thanks again
Groetjes,
Maarten Wiltink
Shalom,
Jim
.
- Follow-Ups:
- Re: WM_COPYDATA
- From: Maarten Wiltink
- Re: WM_COPYDATA
- References:
- WM_COPYDATA
- From: jimbo
- Re: WM_COPYDATA
- From: Maarten Wiltink
- WM_COPYDATA
- Prev by Date: Re: WM_COPYDATA
- Next by Date: Re: WM_COPYDATA
- Previous by thread: Re: WM_COPYDATA
- Next by thread: Re: WM_COPYDATA
- Index(es):
Relevant Pages
|