?
Solved

How2 create some new Forms at runtime ?

Posted on 2005-04-05
6
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 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