Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

How to close a window from code

9 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Timothy Groves

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?

Reply by email

Mattias Gaertner
to Timothy Groves
Show quoted text 5 lines
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?

Do you mean a LCL form?

Form1.Close;

Mattias

Reply by email

Timothy Groves
to Mattias Gaertner
Mattias Gaertner wrote
Do 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?)

Reply by email

Mattias Gaertner
to Timothy Groves
Show quoted text 5 lines
On 12-02-01 12:14 PM, Mattias Gaertner wrote: > Do 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?)

Did you get a compiler error?

This works too:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Close;
end;

Mattias

Reply by email

Timothy Groves
to Mattias Gaertner
Mattias Gaertner wrote
Did you get a compiler error?

No. The program merely hung upon reaching the Close.

Show quoted text 9 lines
This works too: procedure TForm1.Button1Click(Sender: TObject); begin Close; end;

This did not work for me. However, the Form1.Close version did, and that's what I'm using. Thanks!

Reply by email

Mark Morgan Lloyd
to Timothy Groves: Well, I tried just Close from within a method of the form in question, and that didn't…
Timothy Groves wrote 5 lines
On 12-02-01 12:14 PM, Mattias Gaertner wrote: > Do 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?)

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

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Alexsander Rosa
to Rich Saunders

Or even (Self as TForm).Close for that matter.

2012/2/1 Rich Saunders

Show quoted text 10 lines
On 2/1/12 12:49 PM, Timothy Groves wrote: > However, 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.
Atenciosamente, Alexsander da Rosa http://rednaxel.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120201/feeea6e4/attachment.html>

Reply by email

zeljko
to Alexsander Rosa
Alexsander Rosa wrote
Or 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
2012/2/1 Rich Saunders > On 2/1/12 12:49 PM, Timothy Groves wrote: > > However, 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120202/42c79571/attachment.html>

Reply by email