From 09c7e2fe60e25c431d1cea07282f471b8309d2c9 Mon Sep 17 00:00:00 2001 From: "Dmitry D. Chernov" Date: Wed, 20 Sep 2023 02:45:12 +1000 Subject: [PATCH] =?utf8?q?Fix=20LCLRefCount=20warning=20and=20possible=20u?= =?utf8?q?se-after-free=20Verbatim=20warning=20text:=20"WARNING:=20TMenuIt?= =?utf8?q?em.Destroy=20with=20LCLRefCount>0.=20Hint:=20Maybe=20the=20compo?= =?utf8?q?nent=20is=20processing=20an=20event=3F".=20This=20was=20caused?= =?utf8?q?=20by=20a=20complex=20call=20chain=20of=20miRecentFileExecute()?= =?utf8?q?=20->=20OpenMap()=20->=20RefreshRecentMenu()=20->=20RefillRecent?= =?utf8?q?Menu(),=20which=20result=20in=20the=20sender=20menu=20item=20bei?= =?utf8?q?ng=20removed.=20In=20such=20cases,=20Application.ReleaseComponen?= =?utf8?q?t()=20should=20be=20used.=20https://forum.lazarus.freepascal.org?= =?utf8?q?/index.php=3Ftopic=3D33591.0=20-=20Topic:=20[SOLVED]=20How=20to?= =?utf8?q?=20delete=20a=20button=20on=20an=20OnClick=20event=20https://www?= =?utf8?q?.lazarusforum.de/viewtopic.php=3Fp=3D118333=20-=20[gel=C3=B6st]W?= =?utf8?q?as=20tun=20bei:=20Maybe=20the=20component=20is=20processing=20an?= =?utf8?q?=20event=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/editor/f_main.pas | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/editor/f_main.pas b/src/editor/f_main.pas index e4e0643..e2fdc20 100644 --- a/src/editor/f_main.pas +++ b/src/editor/f_main.pas @@ -2554,8 +2554,10 @@ end; procedure TMainForm.miRecentFileExecute (Sender: TObject); var s, fn: AnsiString; + n: LongInt; begin - s := RecentFiles[(Sender as TMenuItem).Tag]; + n := (Sender as TMenuItem).Tag; + s := RecentFiles[n]; fn := g_ExtractWadName(s); if FileExists(fn) then OpenMap(fn, g_ExtractFilePathName(s)) @@ -2585,7 +2587,7 @@ begin else begin menu.Delete(i); - MI.Destroy(); + Application.ReleaseComponent(MI); end; end; -- 2.29.2