Recent

Author Topic: [How to?] Call "EventOnMessage" inside "onClickEvent"  (Read 2534 times)

codeman

  • Jr. Member
  • **
  • Posts: 77
[How to?] Call "EventOnMessage" inside "onClickEvent"
« on: December 01, 2021, 04:13:31 am »
Hello, how to call eventOnMessage inside onClick Event??


Code: Pascal  [Select][+][-]
  1. procedure TForm1.EventOnMessage(var Msg: tagMSG; var Handled: Boolean);
  2. var
  3.   NrFiles, i : Integer;
  4.   Buffer : Array[0..255] of Char;
  5. begin
  6. try
  7.    Handled:=Msg.Message=WM_DROPFILES;
  8.    if not Handled then
  9.      exit;
  10.  
  11.   attachedSelected:=true;
  12.   NrFiles:=DragQueryFile(Msg.Wparam,$FFFFFFFF,Buffer,256);
  13.  
  14. .....
  15. .....
  16.  
  17. finally
  18.     DragFinish(Msg.WParam);
  19. end;
  20.  


Code: Pascal  [Select][+][-]
  1. procedure TForm1.button1Click(Sender: TObject);
  2. begin
  3.        ???? EventOnMessage( ?? );  
  4.    
  5.  Everything i tried, I get that compiling error (Types of actual and formal var parameters must be identical)
  6. end;
  7.  


Thanks for considering my request!
« Last Edit: December 01, 2021, 06:21:30 pm by codeman »
Lazarus v2.02 Win10

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 748
Re: [How to?] Call "EventOnMessage" inside "onClickEvent"
« Reply #1 on: December 01, 2021, 04:45:18 am »
Have you tried to do it standard way?
Code: Pascal  [Select][+][-]
  1. procedure WMDropFiles(var Message : TMessage); message WM_DROPFILES;
  2.  
I haven't checked, but may be there is existing handler for this message?
29.12.2021 - migration to DynamicData 4.1 is completed - complete overhaul of data access driver.
My project still requires full Delphi 2009 support to be ported to Lazarus.
It's time to finally do it, because Delphi 2009 is 12 years old.

jamie

  • Hero Member
  • *****
  • Posts: 5143
Re: [How to?] Call "EventOnMessage" inside "onClickEvent"
« Reply #2 on: December 01, 2021, 01:36:24 pm »
Although you can do as you wish it would be meaningless because the values in the message record would need to contain something valid for that to work manually.

 What you should do is make method of the code body you are executing within that message handler and simply call that method instead. What this does is allows you to also call that same body of code elsewhere without the confusion of message handling which in this case would be a lost, just provide a function body (method) with the actual code you are trying to execute so that both this existing event handler can all it along with your manual click..

 Btw, the TFORM has a handler already for a file drop event...
The only true wisdom is knowing you know nothing

codeman

  • Jr. Member
  • **
  • Posts: 77
Re: [How to?] Call "EventOnMessage" inside "onClickEvent"
« Reply #3 on: December 01, 2021, 06:21:53 pm »
Thank you both! Solved! :)
Lazarus v2.02 Win10

 

TinyPortal © 2005-2018