?
Solved

How2 create some new Forms at runtime ?

Posted on 2005-04-05
6
Medium Priority
?
293 Views
Last Modified: 2010-04-05
I have MainForm and PopupForm.
I would like to create new form base on PopupForm at runtime.
How to do that in MainForm ?

Thank for advance.

=====================================

unit popup;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons, ExtCtrls;

type
  TPopupForm = class(TForm)
    OKBtn: TButton;
    Bevel1: TBevel;
    Label1: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  PopupForm: TPopupForm;

implementation

{$R *.dfm}

end.

=====================================
in MainForm
=====================================
uses Popup;

var
  Popup: TPopupForm;

...
...

     if cbPopup.Checked then
     begin
        try
           Popup := TPopupForm.Create(Self);
           Popup.Parent  := Self;
           Popup.Caption := 'test';
           Popup.Label1.Caption := 'test' ;
           Popup.Show;
        finally
           Popup.Free;
        end;
     end;

=====================================

Why it didn't work ?
I want to create them as normal form, as info Dialogboxs. no wait.
And can show while the application minimized.



0
Comment
Question by:tong111797
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
paulb1989 earned 500 total points
ID: 13705584
Create it without an owner and don't set the parent.
0
 
LVL 5

Expert Comment

by:paulb1989
ID: 13705591
Forgot, if you want your form to show and free in the same method then yoiu're going to have to use ShowModal.

     if cbPopup.Checked then
     begin
        try
           Popup := TPopupForm.Create(nil);
           Popup.Caption := 'test';
           Popup.Label1.Caption := 'test' ;
           Popup.ShowModal;
        finally
           Popup.Free;
        end;
     end;
0
 

Author Comment

by:tong111797
ID: 13705829
Thank again,

Popup.ShowModal; work but my application freeze..
maybe it run in my loops.
Then I use Popup.Show;  and it work well.
Can I remove Popup.free; ?  
Click the [x] button to close the popup windows is ok ?


These is my code.


if cbPopup.Checked then
begin
           Popup := TPopupForm.Create(nil);
           Popup.Caption := 'test';
           Popup.Label1.Caption := 'test' ;
           Popup.Show;
end;



0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:tong111797
ID: 13705858
I just know what ShowModal is:



Use ShowModal to show a form as a modal form.  A modal form is one where the application can’t continue to run until the form is closed. Thus, ShowModal does not return until the form closes. When the form closes, it returns the value of the ModalResult property.

To close a modal form, set its ModalResult property to a nonzero value.

Note:      If the form contains buttons with a ModalResult property set to a value other than mrNone, the form automatically closes when the user clicks one of those buttons and returns the ModalResult value as the return value of ShowModal.

You can check the return value against common return values using the global IsAbortResult, IsAnAllResult, IsNegativeResult, or IsPositiveResult functions.
0
 
LVL 17

Expert Comment

by:geobul
ID: 13706900
Hi,

Use Popup.Release instead of Popup.Free. Try it this way:

  if cbPopup.Checked then
     begin
        if Popup <> nil then
          Popup := TPopupForm.Create(Application);
        try
           Popup.Caption := 'test';
           Popup.Label1.Caption := 'test' ;
           Popup.Show;
        finally
           Popup.Release;
           Popup := nil;
        end;
     end;

Regards, Geo
0
 

Author Comment

by:tong111797
ID: 13711651
It's my fault.  I use Popup.free; so I can't see it.
Just remove those line.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question