🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.rtl.dotnet
3 messages
3 total messages Started by Carsten Schuette Thu, 28 Apr 2005 07:58
d2005.net: Use SendMessage() to "send" object reference?
#82
Author: Carsten Schuette
Date: Thu, 28 Apr 2005 07:58
23 lines
1460 bytes
Hi,

the following code was possible in delphi 7:

  [...]
  SendMessage(FControl.Handle, VM_MEINENACHRICHT, 0, LongInt(Self));
  [...]

Here is the code which should receive the message, this al works fine
in delphi 7 for win32:

  procedure TMeinControl.VMMeineNachricht(var Msg: TMessage);
  var
    Ptr: TControl
  begin
    Ptr:=TControl(Msg.lParam);
  end;

In delphi 2005 I get some strange errors that this is no longer
possible with dotnet. But how can I solve this?

Regards,
Carsten
Re: d2005.net: Use SendMessage() to "send" object reference?
#83
Author: Marc Rohloff TeamB
Date: Thu, 28 Apr 2005 12:16
29 lines
2140 bytes
On 28 Apr 2005 00:58:50 -0700, Carsten Schuette wrote:

>   SendMessage(FControl.Handle, VM_MEINENACHRICHT, 0, LongInt(Self));

>   procedure TMeinControl.VMMeineNachricht(var Msg: TMessage);
>   var
>     Ptr: TControl
>   begin
>     Ptr:=TControl(Msg.lParam);
>   end;

> In delphi 2005 I get some strange errors that this is no longer
> possible with dotnet. But how can I solve this?

You cannot convert a Control to an integer. .NET enforces this and
doesn't allow the standard windows hacks.

You need to redefine the SendMessage method to take an object as the
lParam.

You will also need to define your own TMessage subclass to extract the
lParam as  a TControl.

If you look through the .NET source code for the VCL you should find
examples of how this is done.

-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Re: d2005.net: Use SendMessage() to "send" object reference?
#84
Author: Guido Weber
Date: Fri, 29 Apr 2005 05:59
54 lines
2173 bytes
Hi

we have solved this in D8 as follows: replace the call to SendMessage with a
call
to this function:

function SendMessageObject( hWnd : HWND;
                            Msg : Cardinal;
                            wParam : integer;
                            lParam : TObject) : integer;
var
  hndl : GCHandle;
begin
  hndl := GCHandle.Alloc(lParam);
  result := SendMessage(hWnd, Msg, wParam, integer(IntPtr(hndl)));
end;

and at the receiving end convert back to TObject with:

function GCHandleToObject( i: integer): TObject;
begin
  result := GCHandle(IntPtr(i)).Target as TObject;
end;

HTH
  Guido

"Carsten Schuette" <carsten.schuette@gmx.de> schrieb im Newsbeitrag
news:xn0e1j9dn1w4vd005@newsgroups.borland.com...
> Hi,
>
> the following code was possible in delphi 7:
>
>   [...]
>   SendMessage(FControl.Handle, VM_MEINENACHRICHT, 0, LongInt(Self));
>   [...]
>
> Here is the code which should receive the message, this al works fine
> in delphi 7 for win32:
>
>   procedure TMeinControl.VMMeineNachricht(var Msg: TMessage);
>   var
>     Ptr: TControl
>   begin
>     Ptr:=TControl(Msg.lParam);
>   end;
>
> In delphi 2005 I get some strange errors that this is no longer
> possible with dotnet. But how can I solve this?
>
> Regards,
> Carsten
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads