API - mostrando um showmessage no evento onenter dos componentes visuais |
Top Previous Next |
|
//Question/Problem/Abstract:
Do you ever needed to display a message using the OnEnter event? This example shows how to correctly display a message by using the ShowMessage (or an equivalent function) in OnEnter event.
//Answer:
As you have notice, if you call ShowMessage in OnEnter event, mouse will get a bad behavior. Remember that this problem only occurs when the control executes the OnEnter event after you clicked it with the mouse.
//The trick is by using a user windows message.
const UM_SHOWMESSAGE = WM_USER + 256;
// Define this procedure to catch our 'ShowMessage' user message procedure UMShowMessage(var Message: TMessage); message UM_SHOWMESSAGE;
procedure TForm1.UMShowMessage(var Message: TMessage); begin ShowMessage(PChar(Message.lParam)); end;
//To activate the message you just need to put this code in OnEnter event:
PostMessage(Handle, UM_SHOWMESSAGE, 0, LPARAM(PChar('This is a message'))); |