Solved

Delphi: Define FormStyle fsMDIChild or fsNormal at runtime

Posted on 2013-01-02
2
2,161 Views
Last Modified: 2013-01-02
I have a Vcl.Form that is a MDIChild (FormStyle=fsMDIChild). No I have the requirement that I need this form also as a modal dialog. I tried to change the FormStyle at runtime but that does not work.

In the VCL documentation I found a remark that FormStyle should not be changed at runtime. That's obiously the reason why it doesn't work. A workaround would be to have a copy of that form so that one form has FormStyle=fsNormal and the other FormStyle=fsMDIChild. But this is a maintenance nightmare.

Can somebody help me find a solution to that problem? Maybe someone has a better workaround, etc.?

Regards,
Dirk.
0
Comment
Question by:dirkil2
2 Comments
 

Accepted Solution

by:
dirkil2 earned 0 total points
ID: 38738120
I just found that my question has been aswered before: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20976700.html

Therefore I suggest to close my question.
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 38738185
I suggest to use TFrame container. It is like TForm but without border. So, add TFrame to project. Add all components and code to that unit like you do on your form. Then you can create TForm on runtime as TMdiChild or Dialog. This is the way to put your frame control to other form....

... when you want to create dialog:
procedure TForm1.Button1Click(Sender: TObject);
var
  frm: TFrame1;
  modalFrm: TForm;
begin
  modalFrm := TForm.Create(Self);
  try
    modalFrm.BorderStyle := bsDialog;
    modalFrm.Position := poScreenCenter;
    modalFrm.Width := 500;
    modalFrm.Height := 400;

    frm := TFrame1.CreateParented(modalFrm.Handle);
    frm.Parent := modalFrm;
    frm.Align := alClient;
    frm.Visible := True;

    modalFrm.ShowModal;
  finally
    modalFrm.Free;
  end;
end;

Open in new window


... when you want to put frame on form as mdichild:
var
  frm: TFrame1;
  mdiFrm: TForm;
begin
  mdiFrm := TForm.Create(nil);
  try
    mdiFrm.FormStyle := fsMDIChild;
    mdiFrm.Parent := Self;
    mdiFrm.Width := 500;
    mdiFrm.Height := 400;

    frm := TFrame1.CreateParented(mdiFrm.Handle);
    frm.Parent := mdiFrm;
    frm.Align := alClient;
    frm.Visible := True;

    mdiFrm.Show;
   // mdiFrm.WindowState := wsMaximized;
  finally
  end;

Open in new window


... when you put frame on main form which is not mdiparent but simple form
(can be your TPanel component if want):
var
  frm: TFrame1;
begin
  frm := TFrame1.CreateParented(Self.Handle); // or Panel1.Handle
  frm.Parent := Self;  // or Panel1
  frm.Align := alClient;
  frm.Visible := True;

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now