josh, That is an interesting idea. I shall give it a try and post results when I get back next week.
So all testing in this post was done in both Lazarus 1.6.4 and 1.8.4.
But first...
Ok, I'll admit I messed up. In my last post
OnCloseQ_Test3.zip
Should have been:
OnClose_Test4.zip
Sorry. =/
...I have like 10 or more of these things. >.>
(And in my defence, it went like:
Check code, Compile, Run Program, Shutdown PC ...wait 5min for PC to restart... check folder then Repeat to be sure, then "Now lets see, that was uhm, That folder." *Pretypes forum post*
Which was the wrong folder. >.>)
The project in OnClose_Test4.zip is the one that does Nothing.
OnCloseQ_Test3.zip
Was one I wasn't 100% sure about at the time and still messing with, but hadn't tested it enough at the time I posted to say anything. (I wasn't expecting to be online the day I made the post.)
So I fixed that.
In other news...
OnCloseQ_Test3.zip
Actually works, Kind of...
Sooo, ...yeah.
This works "fine" on Windows Shutdown ...Except... when I combined it in a larger test project (in 1.8.4).
...
private
{ private declarations }
procedure OnEndSession(Sender:Tobject);
...
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnEndSession:=@OnEndSession;
end;
procedure TForm1.OnEndSession(Sender: Tobject);
var
f: textfile;
begin
if not FileExists('.\Test.txt') then
begin
assignfile(f, 'Test.txt');
rewrite(f);
writeln(f,'Testing.');
closefile(f);
end;
end;
In my larger test project (in 1.8.4), it works fine if placed here:
TForm1 = CLASS(TForm)
Memo1: TMemo;
...
procedure EndSession(Sender: TObject);
but in Private I get errors:
unit1.pas(77,18) Error: method identifier expected
unit1.pas(136,30) Error: Incompatible types: got "<address of procedure(TObject);Register>" expected "<procedure variable type of procedure(TObject) of object;Register>"
(These Errors are ONLY in 1.8.4. There are no Errors in 1.6.4)
(From my larger Test Project)
procedure TForm1.EndSession(Sender: TObject);
var
f: textfile;
begin
Memo1.Lines.Add(FormatDateTime('hh:nn:ss:ms AM/PM', Now) + ' - ' + FormatDateTime('MM/DD/YYYY', Now) + ' - ' + 'In EndSession.');
Memo1.Lines.SaveToFile('Testing.log');
if not FileExists('.\Test_EndSession.txt') then
begin
assignfile(f, 'Test_EndSession.txt');
rewrite(f);
writeln(f,'EndSession Worked!');
writeln(f, FormatDateTime('hh:nn:ss:ms AM/PM', Now) + ' - ' + FormatDateTime('MM/DD/YYYY', Now));
closefile(f);
end;
END;
(I tried Form1.Memo1./etc thinking that might have been it, but that only fixes the first error. ...The second error confuses me a little. >.>)
So yeah, I'm going to have to see what that is about.
I think if I use both 'OnCloseQuery' and 'EndSession' it'll fix my issue with saving my INI file on program close and PC Shutdown.
...After I get the error sorted anyways. Cause even though they only happen in 1.8.4, I should look at doing it right. ^-^;
(I'm going to have to update eventually. I thought about waiting till 2.0, but...>.>)
Also, here is my OTT Testing project with everything I tried, if anyone else ever runs into anything like this and wants to try a bunch of things in one go.