?
Solved

Component messaging

Posted on 1998-04-29
14
Medium Priority
?
172 Views
Last Modified: 2010-04-06
I defined my own windows message.  I have a handler procedure.  It works in the form, but not in the component.

The code is as follows:

const
  WM_VVTInterfaceMessage = 1125;

  protected
    procedure WMVVTInterfaceMessage(var Msg: TMessage); message WM_VVTInterfaceMessage;

Additionally, how can I pass a string in the message?
I tried using a PChar in the lParam, but I get GPFs and Delphi exits immediately.

Bryan
0
Comment
Question by:bcrotaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1339402
Hi Bryan

What component are you using as your base class?  (I.e. what are you inheriting from?)  I don't think TComponent has an HWND or a WndProc, so that may explain why your msg handler isn't working.

Also, what method are you currently using to pass a PChar?  How are you sending the message in lParam (PostMessage, SendMessage, Perform)?

JB
0
 
LVL 4

Expert Comment

by:d003303
ID: 1339403
Yo,
like JimBob said, you need a window handle and a window proc. Only descendants of TWinControl have these property/method.
If your message is received in the same process, i.e. the same application, you could typecast a PChar variable in the lParam using LongInt(PString) on the sender and PChar(lParam) on the receiver side.
If your message goes out of process boundaries you cannot transfer pointers, only the direct values of wParam and lParam. To get a string through in this scenario, it is getting tricky.

Slash/d003303
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1339404
Hi doo3303

You are right about TWinControl having these, but you can use a work around.  Look at TThread in Classes.pas.  In particular, look at "AllocateWindow" which is a nested function inside the procedure "AddThread".

Cheers,
JB
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:bcrotaz
ID: 1339405
OK - I used TControl, so that explains that part.

How could I send a string between processes using a message?
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1339406
I'm currently using PostMessage, cos I don't want the sender to wait for an answer.

I sent the PChar in the lParam by typecasting it to an longint.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1339407
If you use PostMessage, you could have a problem.  With SendMessage you could solve your problem, because the calling procedure will then allocate AND free the string.

JB
0
 
LVL 4

Expert Comment

by:d003303
ID: 1339408
Yo,
maybe you yould use the GetWindowText/SetWindowText API functions to work around these things. It also works across process boundaries. Note that this only works if the window text is not used for its standard purpose, like captioning.

Slash/d003303
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339409
To get messages to your component you need to make an invisible window :

 TCDEvents = class(TComponent)
  private
    { Private declarations }
     FWindowHandle: HWND;
     procedure WndProc(var Msg: TMessage);
  protected
    { Protected declarations }
  public
    { Public declarations }
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
  published
    { Published declarations }
  end;

constructor TCDEvents.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FWindowHandle := AllocateHWnd(WndProc);
end;

procedure TCDEvents.WndProc(var Msg: TMessage);
begin
 {handle the messages}
 if message then begin
 end
    else
      Msg.Result := DefWindowProc(FWindowHandle, Msg.Msg, Msg.wParam,         Msg.lParam);
end;

destructor TCDEvents.Destroy;
begin
  DeallocateHWnd(FWindowHandle);
  inherited Destroy;
end;

Regards, ZiF.


0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1339410
Hmmm... This isn't as simple as it could be.
Is there no way of allocating memory with global permissions, so every process can access it?
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1339411
Hi

You can create a global shared memory area using CreateFileMapping.  For an example of this, look for MY comments under the following (unanswered) question:
http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10050013

Cheers,
JB
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1339412
Not easy?  Not much code ....

It's the way delphi does it...

Regards, Zif.
0
 
LVL 1

Accepted Solution

by:
ssite earned 200 total points
ID: 1339413
The right way to pass strings betweek apps is to use Atoms. Better yet, global atoms. Look it up in win32 help. It's pretty simple to do, but the string is limited to 255 chars.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1339414
There is a way to pass message to tControl: by calling the dispatch method eg  myControl.dispatch( userMessage);
0
 
LVL 1

Expert Comment

by:ssite
ID: 1339415
Did you use control.perform ?

maybe 1125 is used as an internal mesage in the component. Try WM_MYMESSAGE = WM_USER + 100

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question