Solved

Delphi: Define FormStyle fsMDIChild or fsNormal at runtime

Posted on 2013-01-02
2
2,224 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 26

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 88
Base1 Encode/Decode 3 77
Wincontrol not (correctly) drawn 15 37
Firemonkey allowing RTL on android 6 28
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…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

816 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

13 Experts available now in Live!

Get 1:1 Help Now