Delphi Message Handlers

When the user double-clicks dbgrid, I show a modeless form.

When they close this form, I want to update the grid.

For this, I tried the following:

1 - Define the custom message constant:

const
  WM_REFRESH_MSG = WM_USER + 1;  //defined in a globally available unit

2 - In the OnClose event of my modeless form, I have the following:

procedure TMyNonModalForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  PostMessage(Self.Handle,WM_REFRESH_MSG,0,0);
end;

3 - In private declarations of a form containing dbGrid, I have the following:

procedure OnRefreshRequest(var Msg: TMessage); message WM_REFRESH_MSG;

...

procedure TMyFormWithADBGrid.OnRefreshRequest(var Msg: TMessage);
begin
  RefreshGrid;
end;

After completing these steps, PostMessage works fine, but the OnRefreshRequest procedure never starts. What am I doing wrong?

+3
source share
5 answers

, Self.Handle, Self . , , (, ). .

+6

, WM_USER , , , TWinControl. WM_APP.

, UM_ WM_, Windows.

+8

, self.handle, . - , .

, WM_REFRESH_MSG ( CheGueVerra ), .

+2

, .

procedure OnRefreshRequest(var Msg: TMessage); message WM_CEA_REFRESH;

procedure OnRefreshRequest(var Msg: TMessage); message WM_REFRESH_MSG;
+1

" ?" Embarcadero embarcadero.public.attachments.

This is basically a custom event that the main form (or any other form / object) subscribes to when the modeless form closes. In the main (or any other) form ...

var
  NonModalForm :TfmNonModalForm;
begin
  NonModalForm := TfmNonModalForm.Create(nil); 
  NonModalForm.Execute(NonModalFormClosingListener);

In the Execute method

procedure TfmNonModalForm.Execute(YourListenerMethod: THeyIClosedEvent);
begin
   FHeyIClosedEvent := YourListenerMethod;
   Show();
end;

If you can’t get to the forum and you need additional code, leave a comment and I will post the missing fragments.

Good luck.

+1
source

Source: https://habr.com/ru/post/1708286/


All Articles