<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> schrieb am Mi., 1. Aug. 2018, 17:28:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Aug 1, 2018, at 9:17 AM, Sven Barth via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-devel@lists.freepascal.org</a>> wrote:<br>
> <br>
> Search the compiler's source for the string 'FREEINSTANCE'; you'll find two locations, one in ngenutil and one in psub. The latter is the one you want. <br>
> <br>
<br>
Yeah, this is the first place I looked but current_structdef is always nil so it never progresses past that point.<br>
<br>
Is this test program not enough to get FreeInstance called? <br>
<br>
program test;<br>
var<br>
obj1: TObject;<br>
begin<br>
obj1 := TObject.Create;<br>
obj1.Free;<br>
end.<br>
<br>
<br>
===========<br>
<br>
function generate_bodyexit_block:tnode;<br>
var<br>
srsym : tsym;<br>
para : tcallparanode;<br>
newstatement : tstatementnode;<br>
oldlocalswitches: tlocalswitches;<br>
begin<br>
result:=internalstatements(newstatement);<br>
<br>
if assigned(current_structdef) then<br>
begin<br>
{ Don't test self and the vmt here. The reason is that }<br>
{ a constructor already checks whether these are valid }<br>
{ before. Further, in case of TThread the thread may }<br>
{ free the class instance right after AfterConstruction }<br>
{ has been called, so it may no longer be valid (JM) }<br>
oldlocalswitches:=current_settings.localswitches;<br>
current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];<br>
<br>
{ a destructor needs a help procedure }<br>
if (current_procinfo.procdef.proctypeoption=potype_destructor) then<br>
begin<br>
if is_class(current_structdef) then<br>
begin<br>
srsym:=search_struct_member(current_structdef,'FREEINSTANCE');<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">If you'd look at the code you quoted you'd see that this is only inserted *inside* a destructor (the check for potype_destructor; current_procinfo is the currently compiled routine). So, no, your code is not enough. You need to declare a class with a destructor, then the code would be entered. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>