List Info

Thread: Sending WM message to TDataModule




Sending WM message to TDataModule
user name
2006-05-22 14:59:21
> Is it just that the handle is not public or not there at all? Try casting as Tcomponent (if possible).

It's not there at all. TDataModule already descends from TComponent, so
that type-cast would do nothing. TComponent doesn't have a handle,
either. The Handle property gets introduced in TWinControl. TDataModule
is not a windowed control. It has a windowed representation in the IDE
to allow you to put other components on it, but that's only at design time.

To send messages to a data module, there needs to be a window available.
You can use the AllocateHWnd function to create a window for receiving
messages. That function expects a method pointer, which the new window
will call whenever a message arrives. Implement the method in the
data-module object. There are a couple of examples of using AllocateHWnd
in the VCL source code.

--
Rob
Sending WM message to TDataModule
user name
2006-05-22 17:07:38
> To send messages to a data module, there needs to be a window
available.
> You can use the AllocateHWnd function to create a window for
receiving
> messages. That function expects a method pointer, which the new
window
> will call whenever a message arrives. Implement the method in the
> data-module object. There are a couple of examples of using
AllocateHWnd
> in the VCL source code.
>;
> --
> Rob
>

Thank you, worked, here is the code (snipped):

type
  TMyDataModule = class(TDataModule)
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    FHWnd: HWND;
  protected
    procedure ProcessWndMessages(var aMsg: TMessage); virtual;
  public
    property Handle:HWND read FHWnd;
......


procedure TMyDataModule.DataModuleCreate(Sender: TObject);
begin
  FHWnd := AllocateHWnd(ProcessWndMessages);
......

procedure TMyDataModule.DataModuleDestroy(Sender: TObject);
begin
  DeallocateHWnd(FHWnd);
......

procedure TMyDataModule.ProcessWndMessages(var aMsg: TMessage);
var done:boolean;
   ; UserInfo:TUserInfo;
begin
  done := False;
  case aMsg.Msg of
   ; wm_MyMessage: begin
      done := True;
      code for this message
    end;
  end;
  if done
    then  aMsg.Result := 0
    else aMsg.Result := DefWindowProc(FHWnd, aMsg.Msg, aMsg.WParam,
aMsg.LParam);

end;


Finally, to post message to MyDataModule I use this code:

PostMeassage( MyDataModule.Handle, WM_MyMessage, 0, 0);

Thank you again
Yours,
Monir








[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )