Pass data via messages
- From: Sidney Egnew <egnew@xxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 18:59:44 -0600
The following web page has good examples of how to pass data via
custom window messages:
http://www.cryer.co.uk/brian/delphi/howto_send_custom_window_message.htm
Here is a sample of the code:
SendMessage(LinkCheckForm.Handle,WM_ANO_MESSAGE,Integer(self),0);
and at the recipient end:
procedure TMyForm.OnAnoMessage(var Msg: TMessage);
var
myObject: TMyClass;
begin
myObject := TMyClass(msg.WParam);
The problem is that I have only been able to get this to work for
simple objects. Here is an example:
type
TLogMsg = record
MessageText: String;
end;
// Sending
LogMsg.MessageText := GetFileName(S);
SendMessage(Application.MainForm.Handle,WM_Log,Integer(LogMsg),0);
// Receiving
procedure TfmMain.OnLog(var Msg: TMessage);
begin
LogMsg := TLogMsg(Msg.WParam);
LogMemo.Lines.Add(LogMsg.MessageText);
end;
This works fine. However if I try to use a more complex object I get
an "Invalid typecast" error in the SendMessage when I try to compile.
TProgressMsg = record
Module: String;
Count: Integer;
end;
// Sending
ProgressMsg.Module := 'Hi There';
ProgressMsg.Cnt := 1;
SendMessage(Application.MainForm.Handle,WM_Progress,Integer(ProgressMsg),0);
Is it possible to pass this more complicated object using WParam and
LParam?
Thanks, Sidney
.
- Follow-Ups:
- Re: Pass data via messages
- From: Rob Kennedy
- Re: Pass data via messages
- Prev by Date: Re: Newbie looking for info on basic graphics with Delphi.
- Next by Date: Re: Delphi App with ActiveX fails under Vista
- Previous by thread: Delphi App with ActiveX fails under Vista
- Next by thread: Re: Pass data via messages
- Index(es):
Relevant Pages
|