Board index » cppbuilder » Dynamic Forms

Dynamic Forms


2003-07-31 05:24:55 AM
cppbuilder23
Dont think this is a complicated question but my brain is starting to ache,
Okay have form number 1 which is a MDI form with two buttons, we click one
button and create a dymanic form called Form A, Form A is a MDI Child,
Form 1 opens number Form 2 from the other button Form 2 is a standard form,
and we now have 3 forms open.
From a button in Form 2, how do can you close the dynamic form ?
I have tried just about everything and it gives me memory errors but still
doesnt close Form A,
In the close event of the dynamic form i have, Action=caFree; But i cant
seem to call the event,
FormA->Close(); gives me memory errors but doesnt close for example.
Metro.
 
 

Re:Dynamic Forms

"Metro" < XXXX@XXXXX.COM >wrote in message
Quote
From a button in Form 2, how do can you close the dynamic form ?
Which one are you referring to exactly? Do you want Form2 to close itself,
or do you want Form2 to close the MDIChild FormA? Your question is very
confusing. You should not mix letters and numbers, try to keep things
consistent please.
Quote
In the close event of the dynamic form i have, Action=caFree;
But i cant seem to call the event, FormA->Close(); gives me
memory errors but doesnt close for example.
Please show your actual code.
Gambit
 

Re:Dynamic Forms

"Metro" < XXXX@XXXXX.COM >wrote:
Quote
[...] From a button in Form 2, how do can you close the
dynamic form ?
There are a number of different issues that the included
sample addresses - like creating the dynamic form a second
time around but it doesn't show multiple instances of the
dynamic form:
//---Project.cpp ---------------------------------------------
#include <vcl.h>
#pragma hdrstop
USEFORM("MainMod.cpp", Main);
USEFORM("Unit2.cpp", Form2);
USEFORM("ChildMod.cpp", MyChild);
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TMain), &Main);
Application->CreateForm(__classid(TForm2), &Form2);
// Remove the mdiChild from auto create list
// Application->CreateForm(__classid(TMyChild), &MyChild);
<snip>
//----Main header ---------------------------------------------
public: // User declarations
void __fastcall CloseChild();
//----Main cpp ------------------------------------------------
#include "Unit2.h"
#include "ChildMod.h"
TMyChild* pChild;
//-------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
pChild = NULL;
}
//-------------------------------------------------------------
void __fastcall TMain::CloseChild()
{
pChild->Close();
pChild = NULL;
}
//-------------------------------------------------------------
void __fastcall TMain::Button1Click(TObject *Sender)
{
if( !pChild )
{
pChild = new TMyChild( this );
}
if( pChild )
{
if( pChild->WindowState == wsMinimized ) pChild->Perform(WM_SYSCOMMAND, SC_RESTORE, 0);
pChild->BringToFront();
pChild->SetFocus();
}
}
//-------------------------------------------------------------
void __fastcall TMain::Button2Click(TObject *Sender)
{
if( Form2->Visible )
{
if( Form2->WindowState == wsMinimized )
Form2->Perform(WM_SYSCOMMAND, SC_RESTORE, 0);
}
else Form2->Visible = true;
Form2->BringToFront();
Form2->SetFocus();
}
//--- Form2 cpp -----------------------------------------------
#include "MainMod.h"
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Main->CloseChild();
}
//--- Child cpp -----------------------------------------------
void __fastcall TMyChild::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//---- end ----------------------------------------------------
~ JD
 

{smallsort}

Re:Dynamic Forms

Okay will try again, my main form opens a dynamic form using this code
try
{
TFrmLookShares* MyForm = new TFrmLookShares(this);
MyForm->Show();
}
catch(...)
{
ShowMessage("Report an error form");
}
//should have openned client.
}
I would like to be able to close this dynamic form from any other form in
the program, this includes other forms that are loaded when the program
loads, Im referring to Options|Forms in Builder.
Also if there are more than one dynamic form created using the code above
how can i pick which one to close ?
Metro.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Metro" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>From a button in Form 2, how do can you close the dynamic form ?

Which one are you referring to exactly? Do you want Form2 to close
itself,
or do you want Form2 to close the MDIChild FormA? Your question is very
confusing. You should not mix letters and numbers, try to keep things
consistent please.

>In the close event of the dynamic form i have, Action=caFree;
>But i cant seem to call the event, FormA->Close(); gives me
>memory errors but doesnt close for example.

Please show your actual code.


Gambit


 

Re:Dynamic Forms

"Metro" < XXXX@XXXXX.COM >wrote:
Quote
[...] I would like to be able to close this dynamic form
from any other form in the program, [...]
I already showed you how to do that. Just include the main
header in the secondary form and call the same function.
Quote
Also if there are more than one dynamic form created using
the code above how can i pick which one to close ?
Programatically distinguishing one form from the rest is not
the issue. How would you propose to know which one the user
wants closed?? You'd be waisting your time building the GUI
and the users time by using it when they can just click on
close.
~ JD
 

Re:Dynamic Forms

Hi
I am using Component Resource files to save and retrieve dynamic form
templates. Typical code is:
procedure TForm1.FileOpen2Accept(Sender: TObject);
begin
NewForm := TNewForm.CreateNew(Application);
ReadComponentResFile(FileOpen2.Dialog.FileName, NewForm);
......
......
NewForm.Show;
end;
procedure TNewForm.SaveCard(TemplateName: string);
begin
WriteComponentResFile(TemplateName, Self);
end;
Everything works fine with labels and data fields, however when reopening a
form that contains a TImage I get the following error:
....exception class ECLassNotFound with message 'Class TImage not found'
Process stopped ...etc.
Any ideas?
TIA
Brian Murphy
 

Re:Dynamic Forms

I discovered that if I drop a TImage component onto the form the code works
perfectly. The TImage itself is never actually used. Is this a bug or is
there something I've missed?
-
BM :-)
"Brian Murphy" < XXXX@XXXXX.COM >wrote in message
Quote
Hi
I am using Component Resource files to save and retrieve dynamic form
templates. Typical code is:

procedure TForm1.FileOpen2Accept(Sender: TObject);
begin
NewForm := TNewForm.CreateNew(Application);
ReadComponentResFile(FileOpen2.Dialog.FileName, NewForm);
......
......
NewForm.Show;
end;

procedure TNewForm.SaveCard(TemplateName: string);
begin
WriteComponentResFile(TemplateName, Self);
end;

Everything works fine with labels and data fields, however when reopening
a
form that contains a TImage I get the following error:

....exception class ECLassNotFound with message 'Class TImage not found'
Process stopped ...etc.

Any ideas?
TIA

Brian Murphy


 

Re:Dynamic Forms

Hi,
Quote
I discovered that if I drop a TImage component onto the form the code
works
perfectly. The TImage itself is never actually used. Is this a bug or is
there something I've missed?
Now that you dropped the TImage on the form, and compiled it,
the compiler added the ExtCtrls unit to your form's unit.
If that unit is missing, and you load the Component Resource file, the unit
has
no way of creating that component, since it has no knowledge of it.
Try removing the TImage and removing the ExtCtrls unit to see if it's still
failing.
If yes, add the unit again, and see if it works then.
If it doesn't work, make a type or so that sums up all possible components
on your form,
that way you're sure the classes get compiled into your program
 

Re:Dynamic Forms

"Roel Messiant/Mephy" wrote
..........
Quote
Now that you dropped the TImage on the form, and compiled it,
the compiler added the ExtCtrls unit to your form's unit.

If that unit is missing, and you load the Component Resource file, the
unit
has
no way of creating that component, since it has no knowledge of it.
ExtCtrls unit was declared!
Quote
Try removing the TImage and removing the ExtCtrls unit to see if it's
still
failing.
If yes, add the unit again, and see if it works then.
Just removing the TImage causes the exception!.
Quote
If it doesn't work, make a type or so that sums up all possible components
on your form,
that way you're sure the classes get compiled into your program

That might work, will give it a try - thanks.
Brian :-)