Solved

Delphi: Define FormStyle fsMDIChild or fsNormal at runtime

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

16 Experts available now in Live!

Get 1:1 Help Now