?
Solved

What is the correct way to work with multiple form ?

Posted on 2007-10-19
14
Medium Priority
?
261 Views
Last Modified: 2010-08-05
Hello guys,

My main form will call the salesform, but it can be called several times, then, what is the correct way to work with multiple form?

procedure TFmenu.ConsultadeVendas1Click(Sender: TObject);
Var
  NewForm : TFSalesForm;
begin
  SMerc      := 'I';
  NewForm := TFSalesForm.Create(Self);
  NewForm.Show;
End

procedure TFmenu.ConsultadeVendas1Click(Sender: TObject);
Var
  NewForm : TFSalesForm;
begin
  SMerc      := 'I';
  FSalesForm:= TFSalesForm.Create(Self);
  FSalesForm.Show;
End;

Or other way...

Thanks


0
Comment
Question by:hidrau
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 8

Accepted Solution

by:
slado2 earned 900 total points
ID: 20111836
You should consider using MDI interface. Set the main form's FormStyle property to fsMDIForm and all your sales or other forms fsMDIChild. Then you can open as many forms as you want and the user will be able to work simultaneosly on them.
0
 
LVL 1

Assisted Solution

by:peterkiers
peterkiers earned 300 total points
ID: 20112648
Code for opening multiple forms:

procedure TForm.CreateMDIChild(const Name: string);
var
  Child: TMDIChild;
begin
  Child := TMDIChild.Create(Application);
  Child.Caption := Name;
end;
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 20114064
if you do not need to keep track of the form, then you do not even need the variable
you can just do

procedure TFmenu.ConsultadeVendas1Click(Sender: TObject);
begin
  SMerc      := 'I';
  With TFSalesForm.Create(Self) do Show;
End;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:hidrau
ID: 20124822
Hello Guys

See the problem that I have and help me to understand it .

SaleForm := TSaleForm.Create(self);
SaleForm.Show

After call 5 times the SaleForm, when I close any windows, any reference in my windows SaleForm gives me an error, when I say refence, like this:

In the form saleForm

With SaleForm do
begin
   Top := 0;
   Width := 600  
End;

Why? How to avoid this?
0
 
LVL 8

Assisted Solution

by:slado2
slado2 earned 900 total points
ID: 20125445
There are 2 design concepts of windows applications: SDI (Single Document Interface) form and MDI (Multiple Document Interface).
SDI means that the user has just one form open and he works only with one instance of "document" (in your case SalesForm). He may not open another SalesForm until the current one is closed <=> he can work only with one form at the time. Typical application is for example Notepad = you can edit only one document (document editor = form)
MDI means that the user open many "documents" (SalesForms) and that the forms are independent. So he may freely open another SalesForm even he has some SalesForms open already. If you know Microsoft Word than you can see that word can open many documents (=forms) at the same time and user can freely work with the document he wants. User can access the documents by Window menu (in standard application menu bar) where he can cascade, tile, minimize windows (MDIChilds) etc.

You have to choose what you want to provide to your users. If you decide for SDI then do not allow opening another SalesForm if one is already displayed.
If you want to use MDI then you will have to store your forms in ObjectList or another control to keep the track of all open forms.
0
 
LVL 1

Author Comment

by:hidrau
ID: 20125625
slado2, when you say MDI application , you mean that all my form will work only inside of my main form, and when I minimize it, it will be inside of my main form ?

is it?
0
 
LVL 8

Expert Comment

by:slado2
ID: 20126747
yes. Your main form has formstyle fsMDIForm and all your child forms have fsMDIChild.
0
 
LVL 17

Assisted Solution

by:TheRealLoki
TheRealLoki earned 300 total points
ID: 20127698
If you want to have 5 salesforms, you should *not* use teh variable name "salesform"
otherwise, you will be overwriting it each time you create a new form
in the salesformpas code wehre you have
>With SaleForm do
>begin
>   Top := 0;
>   Width := 600  
>End;

change it to
With (self as TSalesForm) do
begin
   Top := 0;
   Width := 600  
End;
0
 
LVL 1

Author Comment

by:hidrau
ID: 20133523
TheRealLoki:
From my saleform sometimes I need to call other form and there some part in these forms that I make reference the saleform due to those my queries, like this example:

  sLinha     :=  Fsaleform .QConsultaEstoque_ICns_LINH.AsString;
  sProduto   := Fsaleform .QConsultaEstoque_ICns_CodProd.AsString;
  sDescricao := Fsaleform .QConsultaEstoque_ICns_Descricao_Produto.AsString;
  sCodDePara := Fsaleform .QConsultaEstoque_Icns_Codigo_DePara.AsString;

Then, I got problem here when I do this:

I called my saleform this way:

Var
  NewForm : TFsaleform ;
begin
  SMerc      := 'I';
  NewForm := TFsaleform .Create(Self);
  NewForm.Show;
End

How to work around ?
0
 
LVL 8

Assisted Solution

by:slado2
slado2 earned 900 total points
ID: 20133650
Use ObjectList to store all your SaleForm:
var Forms: TObjectList;

...

Forms := TObjectList.Create(true);
 SMerc      := 'I';
  NewForm := TFsaleform .Create(Self);
  Forms.Add(NewForm);
  NewForm.Show;


Then use Forms to search for appropriate form.
0
 
LVL 1

Author Comment

by:hidrau
ID: 20133717
Must forms be declared in Public variable?
How can I call my form with this objectlist ?
I didn't understand very well
0
 
LVL 1

Author Comment

by:hidrau
ID: 20133856
Let me explain better what I need and what I am having problem:

Imagine a new project:

I have the main form named Form1, on my main form there is a button that call form2, this form2 can be called several times, there is a query on form2 and a button that call form3, on the form3 there is a button that can close adoquery from my form2.

Now you have the process, Imagine that I called 2 or 3 times form2 and form3 from each form2, when I click on the button on form3 that must close the adoquery in form2, it's ok, but when I try in other form3 to do the same thing, I don't have the success,

did you get it?

0
 
LVL 1

Author Comment

by:hidrau
ID: 20134031
I am gonna open another thread
0
 
LVL 1

Author Comment

by:hidrau
ID: 20134037
part of the problem was solved, then I prefered to open another thread
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

807 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