Recent

Author Topic: Why Doesn't my Event Handler Work?  (Read 2614 times)

Laurence

  • Newbie
  • Posts: 6
Why Doesn't my Event Handler Work?
« on: November 07, 2015, 04:43:29 pm »
Hi All
I am trying to write a procedure to stop a file downloading from a WebBrowser.
I am clearly doing something wrong !!
I have declared the class:-
Code: [Select]
Type
 {TStopFileDownloads}
 TStopFileDownloads = Class(TEVSWebBrowser)

Public
Class Procedure Stop_Downloads(Sender:TObject;  ActiveDocument: WordBool; Var cancelDownload :WordBool);

 end;       

I have Declared the type:-
Code: [Select]
Type TStopDownloads  = Procedure (Sender:TObject;  ActiveDocument: WordBool; Var CancelDownload :WordBool) of Object;Register;
  Var Stop_Downloads : TStopDownloads; 

I have started the method (but haven't got that far as the compiler throws out the calling event:-
Code: [Select]
Class Procedure TStopFileDownloads.Stop_Downloads(Sender: TObject;
  ActiveDocument: WordBool; Var cancelDownload: WordBool);
begin

end;

Finally, here is the calling event:-
Code: [Select]
webbrowser2.OnFileDownload :=Stop_Downloads(WebBrowser2 as TObject,True,CancelDownload);
All I get is the error "Error: Incompatible types: got "untyped" expected "<procedure variable type of procedure(TObject,WordBool,var WordBool) of object;Register>"
.


Any help appreciated.....

Laurence

Lazarus Version:- 1.2.6
FPC Version:- 2.6.4
O.S:- Windows 7 Pro
I.E 11
Quitters Never Win. Winners Never Quit

christian1987

  • New Member
  • *
  • Posts: 30
Re: Why Doesn't my Event Handler Work?
« Reply #1 on: November 07, 2015, 04:56:33 pm »
webbrowser2.OnFileDownload :=Stop_Downloads;

or

webbrowser2.OnFileDownload :=@Stop_Downloads;

....something like that

Laurence

  • Newbie
  • Posts: 6
Re:[SOLVED] Why Doesn't my Event Handler Work?
« Reply #2 on: November 07, 2015, 05:10:18 pm »
Hi Christian,
It just compiled.
THANK YOU
THANK YOU
THANK YOU

I have been trying to find out how to do that for about 5 or 6 weeks !!
MSDN, Google, Lazarus FPC I just could not find a solution.
For your info:
The @ symbol created an error because it is a pointer but the first (simplest) solution worked!

I only do this as a hobby, thankfully it isn't my job!! I would be very poor.
Once again
Thanks
Lazarus Version:- 1.2.6
FPC Version:- 2.6.4
O.S:- Windows 7 Pro
I.E 11
Quitters Never Win. Winners Never Quit

 

TinyPortal © 2005-2018