Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Postmessage to Datamodule

656 views
Skip to first unread message

bora

unread,
Jul 21, 2007, 2:45:15 PM7/21/07
to
Can I post a message to a datamodule? It has no handle property. I
remember a demo for creating a handle for a datamodule to use when
calling postmessage function but i'm not sure.

Any ideas?

Johann Campbell

unread,
Jul 21, 2007, 4:54:22 PM7/21/07
to
Here is a code snippet of what I use:

TMyDataModule = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
FHWND : HWND;
procedure WindProc(var Msg : TMessage);
public
property Handle : HWND read FHWND;
end;

procedure TMyDataModule.DataModuleCreate(Sender: TObject);
begin
FHWND := AllocateHWND(WindProc); // get a new window handle
end;

procedure TMyDataModule.DataModuleDestroy(Sender: TObject);
begin
DeallocateHWND(FHWND);
end;

This creates a handle and allows you to post messages to the datamodule.

Johann.

"bora" <bora.a...@gmail.com> wrote in message
news:46a25439$1...@newsgroups.borland.com...

bora

unread,
Jul 21, 2007, 5:22:13 PM7/21/07
to
Just the thing I needed. I have been searching for this for hours :) Thanks

MikeR

unread,
Jul 22, 2007, 8:01:03 AM7/22/07
to
Thanks, this solved a problem for me also.
D7 flags AllocateHWND and deallocateHWND as deprecated. Is there a replacement?
Mike

Peter Below (TeamB)

unread,
Jul 22, 2007, 9:07:33 AM7/22/07
to
MikeR wrote:

The functions moved to another unit as part of the reorganization for
Linux/Kylix compatibility. The versions in Forms.pas are deprecated and
only there for backwards compatibility. The versions you are supposed
to use are in the Classes unit. To get rid of the warning qualify the
called function with the unit name: Classes.AllocateHwnd instead of
just AllocateHwnd.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Francois PIETTE [ICS - MidWare]

unread,
Jul 22, 2007, 1:03:15 PM7/22/07
to
> Thanks, this solved a problem for me also.
> D7 flags AllocateHWND and deallocateHWND as deprecated. Is there a
> replacement?

Yes. Forms.AllocateHWND is replaced by Classes.AllocateHWND.
Just a move from one unit to another so that the forms unit is not taken
into programs which doesn't need the all forms stuff but still need a window
handle. This reduce the size of many console mode programs.

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
francoi...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be

MikeR

unread,
Jul 23, 2007, 10:26:51 AM7/23/07
to
Thanks Peter and Francois.

Franz-Leo Chomse

unread,
Jul 23, 2007, 11:17:06 AM7/23/07
to
On Sun, 22 Jul 2007 08:01:03 -0400, MikeR <nf4lN...@pobox.com>
wrote:

>Thanks, this solved a problem for me also.
>D7 flags AllocateHWND and deallocateHWND as deprecated. Is there a replacement?

There is one in the DSiWin32 unit, since the original ones are not
thread safe.

Regards from Germany

Franz-Leo

Johann Campbell

unread,
Jul 23, 2007, 11:27:00 AM7/23/07
to
Oops, forgot the declaration for the WndProc:

procedure TMyDataModule.WindProc(var Msg: TMessage);
begin
if Msg.Msg = WM_MYMESSAGE then
begin
DoSomething();
end
else
// let the default handler process the message
Msg.Result := DefWindowProc(FHWND, Msg.Msg, Msg.WParam, Msg.LParam);
end;

Johann.

"bora" <bora.a...@gmail.com> wrote in message

news:46a27903$1...@newsgroups.borland.com...

MikeR

unread,
Jul 23, 2007, 1:43:10 PM7/23/07
to
Franz-Leo Chomse wrote:
> There is one in the DSiWin32 unit, since the original ones are not
> thread safe.
>
> Regards from Germany
>
> Franz-Leo
Danke sehr.

Remy Lebeau (TeamB)

unread,
Jul 23, 2007, 2:18:02 PM7/23/07
to

"bora" <bora.a...@gmail.com> wrote in message
news:46a25439$1...@newsgroups.borland.com...

> Can I post a message to a datamodule?

Not directly. You would have to create a separate HWND for that, such as
with the VCL's AllocateHWnd() function, or the Win32 API's CreateWindow/Ex()
function.

> It has no handle property.

It is not a windowed control to begin with. It derives directly from
TComponent. It is not a TWinControl descendant.


Gambit


0 new messages