Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
[SOLVED] Free the Sender
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
SynEdit change font size
by
eldonfsr
[
Today
at 06:58:07 pm]
IDE Coolbar
by
Dreihirn
[
Today
at 05:37:11 pm]
[SOLVED] Codepage issue i...
by
Hartmut
[
Today
at 05:27:18 pm]
A little contribution - T...
by
paxnet_be
[
Today
at 05:08:31 pm]
Lazarus 4.8 on Sourceforg...
by
Dreihirn
[
Today
at 04:57:35 pm]
[New Component] ExtTabCtr...
by
d7_2_laz
[
Today
at 04:35:07 pm]
Installing Lazarus via Ma...
by
Dreihirn
[
Today
at 03:52:56 pm]
Screen abnomally
by
Thaddy
[
Today
at 03:21:30 pm]
XRechnung-for-Delphi now ...
by
sh17
[
Today
at 03:20:09 pm]
Line Numbers on MacOS
by
Thaddy
[
Today
at 03:14:19 pm]
FPC Unleashed (inline var...
by
440bx
[
Today
at 02:09:32 pm]
Sudden errors
by
Xenno
[
Today
at 01:15:27 pm]
[SOLVED] TSaveDialog
by
Zvoni
[
Today
at 12:33:33 pm]
Which Control should I us...
by
J-G
[
Today
at 11:57:57 am]
Questions about 16 color ...
by
jamie
[
Today
at 11:21:01 am]
Pdf Viewer in Pascal
by
Dzandaa
[
Today
at 11:20:08 am]
You can embed Windows Con...
by
Fibonacci
[
Today
at 10:13:32 am]
new JPEG XL in pure Pasca...
by
Tomxe
[
Today
at 08:02:53 am]
Conscious Artificial Inte...
by
schuler
[
Today
at 02:42:53 am]
Implementing an Elo ratin...
by
mas steindorff
[
Today
at 02:22:34 am]
Can /my/ AI help me with ...
by
microxa
[
Today
at 12:56:29 am]
IndySecOpenSSL is now ava...
by
TheMouseAUS
[
Today
at 12:08:51 am]
RunFormula: math expressi...
by
stormray
[June 17, 2026, 10:32:05 pm]
Canvas size
by
Thaddy
[June 17, 2026, 07:15:50 pm]
What am I missing here? [...
by
Thaddy
[June 17, 2026, 03:39:02 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Free the Sender (Read 2331 times)
lainz
Hero Member
Posts: 4743
Web, Desktop & Android developer
[SOLVED] Free the Sender
«
on:
November 29, 2018, 12:08:22 am »
Hi, I need to free the sender!
btn1.OnClick :=@OnClick;
...OnClick(Sender: TObject)
if bool1 then
Sender.Free;
But this sometimes causes an exception, there's a safe way to do this? Thanks.
«
Last Edit: November 29, 2018, 08:34:48 pm by lainz
»
Logged
https://lainz.github.io/
wp
Hero Member
Posts: 13586
Re: Free the Sender
«
Reply #1 on:
November 29, 2018, 12:30:13 am »
You cannot destroy the Sender by calling Free in the event handler because the rest of the routine is normally processed and will crash if the sender is needed but does not exist any more. Instead, put the request to delete the Sender into the message loop of the application, i.e. use Application.QueueAsyncCall. Then the Free will be handled after the OnClick processing has finished.
This works
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
AsyncFree
(
AData
:
PtrInt
)
;
begin
TObject
(
AData
)
.
Free
;
end
;
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
begin
Application
.
QueueAsyncCall
(
@
AsyncFree
,
PtrInt
(
Sender
)
)
;
end
;
Logged
Martin_fr
Administrator
Hero Member
Posts: 12437
Debugger - SynEdit - and more
Re: Free the Sender
«
Reply #2 on:
November 29, 2018, 01:21:12 am »
https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tapplication.releasecomponent.html
Logged
Ide Tools, Code completion and more
/
IDE cool features
/
Debugger Status
lainz
Hero Member
Posts: 4743
Web, Desktop & Android developer
Re: Free the Sender
«
Reply #3 on:
November 29, 2018, 08:34:37 pm »
Thanks, it works fine =)
Logged
https://lainz.github.io/
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
[SOLVED] Free the Sender
TinyPortal
© 2005-2018