Recent

Author Topic: How to open a new form?  (Read 8031 times)

stab

  • Full Member
  • ***
  • Posts: 234
How to open a new form?
« on: May 21, 2010, 10:00:57 am »
Hi all,

In an app I added an aboutbox and in my main-unit a uses clause like:

uses AboutBox;

From a menuitem: "About" the following code is supposed to show
the AboutBox.

procedure TfrmPushServer.AboutClick(Sender: TObject);
begin
  frmAboutBox.ShowModal;
end;

But, clicking the menuitem the app stops with:

Acess violation

Press OK to ignore and risk data corruption
Press Cancel to kill program.

Guessing that the aboutbox is unknown to the app,
but doing like above is the way I'm used to specify secondary forms in Delphi.

How am I supposed to achieve what I want?

Second question: Is there some setting to avoid lazarus to start
with an empty project?

Regards
Staffan :o

Leledumbo

  • Hero Member
  • *****
  • Posts: 8432
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to open a new form?
« Reply #1 on: May 21, 2010, 10:09:49 am »
Quote
How am I supposed to achieve what I want?
What about:
Code: [Select]
begin
  with TfrmAboutBox.Create(Self) do
    try
      ShowModal;
    finally
      Free;
    end;
end;
ShowModal requires the called form to have parent the calling form (at least that's what I understood about modal dialogs).
Quote
Is there some setting to avoid lazarus to start with an empty project?
Read this. Find the word "session" there.

stab

  • Full Member
  • ***
  • Posts: 234
Re: How to open a new form?
« Reply #2 on: May 21, 2010, 10:35:59 am »
But my aboutbox is set as autocreated in project options.
Wouldn't that indicate that it is already created when
frmAboutBox is issued?

Staffan

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: How to open a new form?
« Reply #3 on: May 21, 2010, 10:54:15 am »
Please always report Lazarus/FPC Version, OS, Widgetset.

I cannot reproduce the problem using:
Lazarus 0.9.29 r25550M FPC 2.4.0 i386-linux-gtk 2 (beta)

stab

  • Full Member
  • ***
  • Posts: 234
Re: How to open a new form?
« Reply #4 on: May 21, 2010, 11:02:30 am »
Lazarus: 0.9.28.2 beta
FPC:      2.2.4
SVN rev:22279

OS: Windows XP professional sp 3

Staffan

stab

  • Full Member
  • ***
  • Posts: 234
Re: How to open a new form?
« Reply #5 on: May 21, 2010, 11:38:13 am »
All of sudden it works to show the AboutBox.

Didn't need frmAboutBox.Create(Self) as the form was autocreated

Regards
Staffan

 

TinyPortal © 2005-2018