[fpc-pascal] Generic way to pre-maturely exit TCustomApplication without memory leaks
Michael Van Canneyt
michael at freepascal.org
Thu Oct 13 09:41:23 CEST 2016
On Wed, 12 Oct 2016, grouchysmurf wrote:
> Hi.
>
> Is there a way to pre-maturely halt TCustomApplication without causing
> memory leaks?
>
> Say, I have a code, where TH is a Class(TCustomApplication):
>
> ph := TH.Create(Nil);
> ph.Initialize;
> ph.ProcessOptions;
> ph.Run;
> ph.Free;
>
> When options are processed, it may happen the program needs to halt,
> when provided with improper parameters, for example. In such a case,
> I would call Help method:
>
> Procedure TH.Help(ExitCode : Byte = 0; ErrStr : String = '');
> Begin
>
> { do stuff }
> Halt(ExitCode);
> End;
>
> Now, when this happens, ph is not freed, causing a minor memory leak.
> I don't want that. Is there a way to terminate a program with Halt but
> also making sure the memory has been freed properly?
Call Terminate and exit properly ?
TCustomApplication has an exitcode property which will set the global exit
code.
Michael.
More information about the fpc-pascal
mailing list