Forum > General
[Solved] Exception "In HandlerObject reference is Nil" from frmActivate
Wilko500:
Thanks Benny
--- Quote --- Application.QueueAsyncCall
--- End quote ---
I think this is probably the approach I was hoping for. This is new to me so I'll do some reading on this and give it a try. Thanks also for your offer on MessageQueue. I'll get back to you if and when I need to go that route. I have not yet tried threads. It is a subject I would like to get familiar with but right now I have more than enough to occupy my time.
Wilko500:
--- Quote from: cdbc on March 13, 2025, 04:18:11 pm ---You should read up on 'Application.QueueAsyncCall(@MyProc,someint64var);'
--- End quote ---
Thanks Benny. Works a treat. Two questions.
In my case I do not need to pass a value as in the Wiki example with FCounter. I tried to leave it out re-coding the procedure definition(s) but didn't work, something like wrong number of arguments. I have added a dummy value in my program.
--- Quote --- Application.QueueAsyncCall(@Async,FCounter);
--- End quote ---
Second can the QueueAsyncCall be called from a procedure in a different unit? I will probably restructure the code in my frmActivate so that is not needed and I always expected to need to do that as part of my development. Just curious.
cdbc:
Hi
Yes, you just pass in a dummy variable, when not used.
No, you cannot change the callback signature, IT HAS TO BE:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TAsyncProc = procedure (aData: ptrint) of object;A #2:
'Application' lives in unit 'Forms', basically the GUI apparatus of Lazarus.
If you want to use it in another unit, it's possible if you include unit 'Forms' in the other unit's uses clause...
BUT ...if you do MVP or other sort of programming, where you separate Business logic and user interface, you might not want to have GUI-stuff in your backend / business-end...
One solution is to define a Method with the same signature as 'Application.QueueAsyncCall' and then at runtime assign your alias method like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---/// this is your other unit ///var MyQAC: TQac; implementation
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TForm1.FormCreate(Sender: TObject);begin MyQAC:= @Application.QueueAsyncCall;end; Then you don't have to have 'Forms' in your other unit and you can use it by calling
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- MyQAC(@MyClass.HandleAC,SomePtrintParam); HTH
Regards Benny
Wilko500:
Thank you Benny for explanations and suggested workarounds, very helpful. Was just having a chuckle looking at your strap line. “If it ain’t broken don’t fix it”. Very appropriate here. You have provided a solution to my original issue so I’ll just review my coding and avoid unnecessary complication.
cdbc:
Hi
No worries mate, you're welcome ;)
...Still think you should go the 'Thread' route though 8-)
Well, you know where to find me...
Regards Benny
Navigation
[0] Message Index
[*] Previous page