finalization

Hi everyone!

Can anyone tell me why the [b]finalization[/b] part of my unit below does not run? The initialization part is okay, since i can see the [b]it works?[/b] message popping up, unlike in the finalization section.
Finalization parts do not always run?

What i'm trying to realize is the when the program starts this unit creates a TStringList object and during the program run i add some text to it and then when i quit this unit should append this current log to the ones saved in the logfile.

[code]
initialization
{letrehozza a LOGot}
CurrentLog:=TStringList.Create;

showmessage('it works?');



finalization
{lementi a LOGot, hozzadva a regihez}

showmessage('it works?');
with TStringList.Create do
try
if FileExists(LOGFILE) then LoadFromFile(LOGFILE);
AddStrings(CurrentLog);
SaveToFile(LOGFILE);
finally
Free;
CurrentLog.Free;
end;
end.
[/code]


thanks for your help,
malacka

Comments

  • : Hi everyone!
    :
    : Can anyone tell me why the [b]finalization[/b] part of my unit below does not run? The initialization part is okay, since i can see the [b]it works?[/b] message popping up, unlike in the finalization section.
    : Finalization parts do not always run?
    :
    : What i'm trying to realize is the when the program starts this unit creates a TStringList object and during the program run i add some text to it and then when i quit this unit should append this current log to the ones saved in the logfile.
    :
    : [code]
    : initialization
    : {letrehozza a LOGot}
    : CurrentLog:=TStringList.Create;
    :
    : showmessage('it works?');
    :
    :
    :
    : finalization
    : {lementi a LOGot, hozzadva a regihez}
    :
    : showmessage('it works?');
    : with TStringList.Create do
    : try
    : if FileExists(LOGFILE) then LoadFromFile(LOGFILE);
    : AddStrings(CurrentLog);
    : SaveToFile(LOGFILE);
    : finally
    : Free;
    : CurrentLog.Free;
    : end;
    : end.
    : [/code]
    :
    :
    : thanks for your help,
    : malacka
    :
    The finalization parts only run, if the program is terminated correctly. So if your program exits due to a fatal error, the finalization part won't run. That is the only reason I can think of, why the finalization won't run.
  • : : Hi everyone!
    : :
    : : Can anyone tell me why the [b]finalization[/b] part of my unit below does not run? The initialization part is okay, since i can see the [b]it works?[/b] message popping up, unlike in the finalization section.
    : : Finalization parts do not always run?
    : :
    : : What i'm trying to realize is the when the program starts this unit creates a TStringList object and during the program run i add some text to it and then when i quit this unit should append this current log to the ones saved in the logfile.
    : :
    : : [code]
    : : initialization
    : : {letrehozza a LOGot}
    : : CurrentLog:=TStringList.Create;
    : :
    : : showmessage('it works?');
    : :
    : :
    : :
    : : finalization
    : : {lementi a LOGot, hozzadva a regihez}
    : :
    : : showmessage('it works?');
    : : with TStringList.Create do
    : : try
    : : if FileExists(LOGFILE) then LoadFromFile(LOGFILE);
    : : AddStrings(CurrentLog);
    : : SaveToFile(LOGFILE);
    : : finally
    : : Free;
    : : CurrentLog.Free;
    : : end;
    : : end.
    : : [/code]
    : :
    : :
    : : thanks for your help,
    : : malacka
    : :
    : The finalization parts only run, if the program is terminated correctly. So if your program exits due to a fatal error, the finalization part won't run. That is the only reason I can think of, why the finalization won't run.
    :

    Hello!

    You havent told what to set free. Thats why ...


  • : : : Hi everyone!
    : : :
    : : : Can anyone tell me why the [b]finalization[/b] part of my unit below does not run? The initialization part is okay, since i can see the [b]it works?[/b] message popping up, unlike in the finalization section.
    : : : Finalization parts do not always run?
    : : :
    : : : What i'm trying to realize is the when the program starts this unit creates a TStringList object and during the program run i add some text to it and then when i quit this unit should append this current log to the ones saved in the logfile.
    : : :
    : : : [code]
    : : : initialization
    : : : {letrehozza a LOGot}
    : : : CurrentLog:=TStringList.Create;
    : : :
    : : : showmessage('it works?');
    : : :
    : : :
    : : :
    : : : finalization
    : : : {lementi a LOGot, hozzadva a regihez}
    : : :
    : : : showmessage('it works?');
    : : : with TStringList.Create do
    : : : try
    : : : if FileExists(LOGFILE) then LoadFromFile(LOGFILE);
    : : : AddStrings(CurrentLog);
    : : : SaveToFile(LOGFILE);
    : : : finally
    : : : Free;
    : : : CurrentLog.Free;
    : : : end;
    : : : end.
    : : : [/code]
    : : :
    : : :
    : : : thanks for your help,
    : : : malacka
    : : :
    : : The finalization parts only run, if the program is terminated correctly. So if your program exits due to a fatal error, the finalization part won't run. That is the only reason I can think of, why the finalization won't run.
    : :
    :
    : Hello!
    :
    : You havent told what to set free. Thats why ...
    :
    :
    :
    That's not the problem, because calling a method without specifying the object is a compiler-error not a runtime-error. And he did specify which object to free with the "with" reserved word.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories