?
Solved

Delphi: Define FormStyle fsMDIChild or fsNormal at runtime

Posted on 2013-01-02
2
Medium Priority
?
2,467 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
[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
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 27

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

770 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