I've googled this, and I've hunted through the documentation, and I cannot find an answer. I have an app that I'm working on, the graphics portion of which largely just seeds what used to be a console app. I want it so that when the 'Go' button is clicked, the window closes once the main program is complete. How do I code this?
Mailing lists / lazarus / 2012-02
How to close a window from code
9 messages · 6 people · –
- TTimothy Groves 3
- MMattias Gaertner 2
- AAlexsander Rosa 1
- MMark Morgan Lloyd 1
- RRich Saunders 1
- Zzeljko 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Show quoted text 5 lines
Do you mean a LCL form?
Form1.Close;Mattias
Mattias Gaertner wroteDo you mean a LCL form? Form1.Close;
Well, I tried just Close from within a method of the form in question, and that didn't work. This did. Any explanation as to why? (Perhaps the fact that close is also a Pascal reserved word?)
Show quoted text 5 lines
Did you get a compiler error?
This works too:
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;Mattias
Mattias Gaertner wroteDid you get a compiler error?
No. The program merely hung upon reaching the Close.
Show quoted text 9 lines
This did not work for me. However, the Form1.Close version did, and that's what I'm using. Thanks!
Well, I tried just Close from within a method of the form in question, and that didn't…
Timothy Groves wrote 5 lines
Not so much a reserved word as a predefined procedure if you're pulling in the standard libraries.
http://www.freepascal.org/docs-html/rtl/system/filefunctions.html
No. The program merely hung upon reaching the Close. This did not work for me. However,…
Timothy Groves wroteHowever, the Form1.Close version did, and that's what I'm using. Thanks!
Tim-
Note that using Self.Close; would be safer and much preferred over Form1.Close; when called within a TForm1 class method.
It does not rely on the Form1 instance reference to be present and usable.
Or even (Self as TForm).Close for that matter.
2012/2/1 Rich Saunders
Show quoted text 10 lines
Alexsander Rosa wroteOr even (Self as TForm).Close for that matter.
What if he calls Close from class which isn't TForm ? Form1.Close can be used, but in that case he must take care of Form1 ... anyway it's bad programming tehnique.
zeljko
Show quoted text 14 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120202/42c79571/attachment.html>
