Cannot create form. No MDI forms are currently active.

Hi,

It's been a while since I last worked on a Delphi project and I'm
quite rusty in Delphi.

I have a MDI form and a child form.

In the main MDIForm, I have the following that runs when
a configuration file isn't found:

       cd := TConfigDialog.Create(nil);
       cd.ShowModal;
       PostMessage(self.handle, WM_CLOSE, 0, 0);
       Screen.Cursor := crDefault;

But once it hits the first line, it gives me the warning as
mentioned in the subject.  I wrote this code a while back
and I'm not exactly sure what the PostMessage() part does
right now; but I think it closes the main form as well
when the configuration dialog closes.

Can someone point out which part of the project configuration
do I set the MDI form active?

Thanks

Edmund
0
Edmund
1/5/2015 9:31:41 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

4 Replies
2934 Views

Similar Articles

[PageSpeed] 27
Get it on Google Play
Get it on Apple App Store

Edmund wrote:

> In the main MDIForm, I have the following that runs when a
> configuration file isn't found:
<snip>
> But once it hits the first line, it gives me the warning as
> mentioned in the subject. 

The only way you can get that particular error on that particular line of 
code is if either:

1) TConfigDialog's FormStyle property is set to fsMDIChild and TConfigDialog 
is being created before the MainForm (or its MDI client window) has been 
created, such as in the MainForm's OnCreate event.

2) the MainForm's FormStyle is not set to fsMDIForm. 

If TConfigDialog's FormStyle really is set to fsMDIChild, keep in mind that 
you can't use ShowModal() with an fsMDIChild form, it will ignore the request 
and raise an EInvalidOperation exception.

> I wrote this code a while back and I'm not exactly sure what
> the PostMessage() part does right now;

It is causing the calling Form (which I assume is the MainForm) to close 
itself.  If I had to guess, I would think that if the config file is missing, 
you are displaying the dialog, and then terminating the app afterwards.

> but I think it closes the main form as well when the configuration dialog 
closes.

If Self is the MainForm, then yes.

> Can someone point out which part of the project configuration do I set
> the MDI form active?

The MainForm's FormStyle has to be set to fsMDIForm, and the MainForm has 
to be fully created and assigned to the Application.MainForm property before 
any fsMDIForm forms can be created.

--
Remy Lebeau (TeamB)
0
Remy
1/5/2015 6:46:53 PM
Edmund Wong wrote:

> Hi,
> 
> It's been a while since I last worked on a Delphi project and I'm
> quite rusty in Delphi.
> 
> I have a MDI form and a child form.
> 
> In the main MDIForm, I have the following that runs when
> a configuration file isn't found:
> 
>        cd := TConfigDialog.Create(nil);
>        cd.ShowModal;
>        PostMessage(self.handle, WM_CLOSE, 0, 0);
>        Screen.Cursor := crDefault;
> 
> But once it hits the first line, it gives me the warning as
> mentioned in the subject.  I wrote this code a while back
> and I'm not exactly sure what the PostMessage() part does
> right now; but I think it closes the main form as well
> when the configuration dialog closes.

Check the formstyle of the TConfigDialog form class. If the formstyle
is fsMdiChild set it to fsNormal. The code is probably executing before
Application.Mainform has been set to the main form reference, and in
this situation you cannot create MDi child forms yet since they cannot
find their parent.



-- 
Peter Below (TeamB)
0
Peter
1/5/2015 6:48:02 PM
Remy Lebeau (TeamB) wrote:
> Edmund wrote:
>
>> In the main MDIForm, I have the following that runs when a
>> configuration file isn't found:
> <snip>
>> But once it hits the first line, it gives me the warning as
>> mentioned in the subject.
>
> The only way you can get that particular error on that particular line of
> code is if either:
>
> 1) TConfigDialog's FormStyle property is set to fsMDIChild and TConfigDialog
> is being created before the MainForm (or its MDI client window) has been
> created, such as in the MainForm's OnCreate event.

Ah.  TConfigDialog's FormStyle is set to fsStayOnTop.  And yeah, that
code is in the MainForm's onCreate event.

>> Can someone point out which part of the project configuration do I set
>> the MDI form active?
>
> The MainForm's FormStyle has to be set to fsMDIForm, and the MainForm has
> to be fully created and assigned to the Application.MainForm property before
> any fsMDIForm forms can be created.

Hmm.  I was hoping to run a config dialog if the configuration file
doesn't exist.  But apparently, this isn't the right way of doing it.
Particularly in the onCreate event.

I think I'll need to use another way of doing this.

Thanks Remy!
0
Edmund
1/6/2015 12:17:12 AM
Edmund wrote:

> TConfigDialog's FormStyle is set to fsStayOnTop.

Then you cannot be getting the "No MDI forms are currently active" error 
on the line of code you indicated.  Only fsMDIChild Forms can raise that 
particular error:

{code}
procedure TCustomForm.CreateWindowHandle(const Params: TCreateParams);
var
  CreateStruct: TMDICreateStruct;
  NewParams: TCreateParams;
begin
  if (FormStyle = fsMDIChild) and not (csDesigning in ComponentState) then 
// <-- note the FormStyle check!
  begin
    if (Application.MainForm = nil) or
      (Application.MainForm.ClientHandle = 0) then
      raise EInvalidOperation.Create(SNoMDIForm); // <-- exception raised 
here!
  ...
end;
{code}

No other code in the VCL raises that particular error message.  This is the 
only spot.

> Hmm.  I was hoping to run a config dialog if the configuration
> file doesn't exist.

You can certainly do that.  I would do it differently, though.  Instead of 
using the MainForm's OnCreate event, I would do the check in the .dpr file 
itself before creating the MainForm at all, eg:

{code}
Application.Initialize;
if not FileExists(ConfigFileName) then
begin
  cd := TConfigDialog.Create(nil);
  try
    if cd.ShowModal <> mrOk then
      Exit;
  finally
    cd.Free;
  end;
end;
Application.CreateForm(TForm1, Form1);
Application.Run;
{code}

--
Remy Lebeau (TeamB)
0
Remy
1/6/2015 12:30:56 AM
Reply:

Similar Artilces:

Error message "Cannot creat form. No MDI Forms currently active"
Hello, In C++ Builder 2010, when I try to load a MDI Form DLL from Calling App I get the above error message. The code to call the DLL is as follows; TApplication *ThisApp = NULL; HWND AppHandle; //--------------------------------------------------------------------------- int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) { if (reason == DLL_PROCESS_DETACH) { if (ThisApp) Application = ThisApp; } return 1; } //--------------------------------------------------------------------------- void ShowMDI_OpsProgressionModal...

Forms or No Forms
Hope this isn't a repeat.  I looked and didn't find anything. Say for example you had a web page with around 20 fields retrive and update to a database with differing datatypes.  Some fields will have some special controls (dropdowns, radios, buttons, etc) that interact with other parts of the page.  What is the best and/or most efficient code to make the page. Would you use a Formview bound to a standard ADO.net SQL connection and edit the templates. Use a Formview bound to an Object Data Source and edit within the templates. Or use an Object Data Source and bind the...

Calling MDI Form from antoher MDI Form
Hi I have a MDI project where there are two MDI DLL's. When calling the two forms from the main screen they work perfectly fine. However, I do have a need to go straight to the other MDI Form from the first MDI and vice versa. Everything I tried results in a access exception. What I am trying to do is to return to the MDI main form then go to the form required next. The MDI are created in line with the C++ Builder 6 Dev Guide - Using Forms in DLL's. Many Thanks Ian Broome ...

Delphi XE3 MDI Forms Question variables talking between child forms
Hi All, I chose an MDI forms program because I wanted to handle a number of open documents at the same time inside the same container program. The MainForm basically just creates a new MDIChild with Child:= TTextChildForm.Create(Application); as needed. The MDIChild forms work well - they can open the required files and table the results. The child forms store the name of the open file and the contents of the file in a variable and then after a little manipulation table it in a StringGrid. My problem is that if I have two forms open the variables "talk" between the child for...

Later created form always above earlier created form.
From some reason both of my C++Builders XE2 and XE5 have started to behave so that all the time the later created form is above the earlier created form. See three codes below: THE FIRST FORM CODE #include <vcl.h> #pragma hdrstop #include "Unit6.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm6 *Form6; //--------------------------------------------------------------------------- __fastcall TForm6::TForm6(TComponent* Owner) : TForm(Owner) { } THE SEC...

Later created form always above earlier created form.
From some reason both of my C++Builders XE2 and XE5 have started to behave so that all the time the later created form is above the earlier created form. See three codes below: THE FIRST FORM CODE #include <vcl.h> #pragma hdrstop #include "Unit6.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm6 *Form6; //--------------------------------------------------------------------------- __fastcall TForm6::TForm6(TComponent* Owner) : TForm(Owner) { } THE SEC...

Dedecting the form behind the active form
When Form1 is active I call Form2 ( showmodal) now Form1 is visible and behind the Form2. I close Form2 , now Form1 is alone & active then i call Form3 (showmodal),now Form1 is visible and behind the activeform Form3. Now i need the name of the *visible form behind the active form* ( which is Form1 ) I tried Screen.Forms[1].Name but i got Form2 not Form1 because i called it & close a few seconds ago. How can i detect the form which is visible & behind the active form ? Thank You Melissa Torn wrote: > When Form1 is active > I call Form2 ( showmodal) ...

How to use C++ Builder form in Delphi form ?
Dear all, I can call a Delphi form in C++ Builder project, but I can not call a C++ Builder form in a Delphi form? Help me please! Thank you very much! Nguyen Duy Tuan Hi Tuan, > I can call a Delphi form in C++ Builder project, but I can not call a C++ Builder form in a Delphi form? That's correct... > Nguyen Duy Tuan Groetjes, Bob Swart -- Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi CodeGear Technology Partner -- CodeGear RAD Studio Reseller (BeNeLux) Delphi Win32 & .NET books on Lulu.com: http://stores....

Windows application cloas other form from current form
in windows application how to close one form being i other form, that is there are 2 forms visble form1 & form 2 i want to close form1 from form2  code behind ,      Regards Pragash TChennai I assume that you are opening [Form2] from [Form1] You may use the following[like] codeto open a new form2 instance from Form1 Form1 Code behind: //Form1 button1 click event handler private void button1_Click(object sender, EventArgs e) { //Creating new instance of form Form2 frm=new Form2(this); frm.show(); } in t...

Using a Forms creator just to create forms?
Has anyone just used one of the forms packages (Creator or Enterprise) only to create forms?...

form action when dynamically create form control
Hi, When I use <asp:literal> in my form and render it as a iframe during runtime,everything is fine except it always automatically add action attribute to the form and set the attribute's value to the iframe src attribute.How can I remove(avoid) this action attribute being generate because it causes some weird problem.Thanks Hi there, Can you post a code sample of what's going on? I'm not following where the action attribute comes into play here. Thanks.--Brian DesmondWindows Server MVP - Directory Serviceshttp://www.briandesmond.com In the pageload,I have the following code:...

forms and form validation
am new to asp. i have recently been given the task of redisigning an existing website. the old site included a few forms which i have incorporated into the new site layout. unfortunately, since the redesign, the forms no longer work. i have tried to be as detailed as possible, i am quite sure that all the links are in order. i am assuming that their must be something simple that i have neglected as i have not changed the .js files or the path locations. please advise. Thank you. Hi primalxx, Please let us know, what is not working, why it is not working, and what kind of error...

Creating Form or Using Iframe with external form PROBLEM
Hi all, I have a little email form I wish to use in DNN3.First I tried using the Text/HTML module for the html source, but that didn't work.Then I tried Codegalaxy Formcreator, but that didn't work either.Since other form creators have to be bought, I was looking for a different solution.So I try to link an Iframe to a HTML page which is uploaded to the host folder (can't upload .htm or .html into the admin folder).But then that iframe adds http:// to the link. I.E.: http://test.html.Could someone help me out here please? Cause I am lost.Erik Lueskenwww.cupido-online.nlhttp://netherlands.dnn...

Web resources about - Cannot create form. No MDI forms are currently active. - embarcadero.delphi.general

Sean Penn took meeting in jungle with 'El Chapo'
USA TODAY Sean Penn took meeting in jungle with 'El Chapo' USA TODAY Sean Penn stunned Hollywood again, and not for his acting. Penn, the ...

AP News Guide: A look at the record Powerball drawing
Fox News AP News Guide: A look at the record Powerball drawing Fox News DES MOINES, Iowa – People who bought Powerball tickets have more time ...

Sunday Morning Politicos Weigh In – Barely – On Sean Penn & El Chapo
Oddly enough, Sean Penn ’s controversial Rolling Stone interview with Joaquin “ El Chapo ” Guzman didn’t bring the expected barrage of anti-Hollywood ...

Boyfriend finds American artist Ashley Olsen ‘strangled’ in Florence apartment
POLICE have vowed “maximum attention” to find the killer of an American artist found dead in her Florence apartment, as Italy’s expat community ...

Obama, in State of Union speech, to draw contrast with Republican 'gloom'
By Roberta Rampton WASHINGTON (Reuters) - President Barack Obama will paint an optimistic picture in his final State of the Union televised address ...

'Outlander' Stars Caitriona Balfe & Sam Heughan Attend BAFTA Tea Before Golden Globes!
Caitriona Balfe and Sam Heughan arrive at the 2016 BAFTA Los Angeles Awards Season Tea held at the Four Seasons Hotel on Saturday (January 9) ...

In Oregon standoff, local sheriff embraces the spectacle
Los Angeles Times In Oregon standoff, local sheriff embraces the spectacle Los Angeles Times When Harney County Sheriff David Ward met with ...

Kosovo: Anti-government protests turn violent as 24 police officers sustain injuries
Protesters burn down government headquarters in capital Pristina.


Germany: Authorities Must Probe Cologne Assault Links
Hindustan Times Germany: Authorities Must Probe Cologne Assault Links New York Times BERLIN — Germany's justice minister says authorities ...

Resources last updated: 1/10/2016 7:03:59 PM