I am relatively new to delphi.

what i am try to do it to open a new form from the main one as a pop-up window, let the user input certain values in there (two integers and a check box), and use these values as parameters in a procedure to call in the main form (to create a new object), when the user clicks the 'done' button in the pop-up form, also closing & freeing the popup.

i cannot add the main form in the uses list of the pop-up form, as this creates a circular reference, because the pop-up form is in the 'uses' list in the main form in order to make it appear on the click of a button. but now i cannot call the procedure in the main form (to create the new object with the inputted parameters) from the pop-up form.
what do i do?
much appreciated

Recommended Answers

All 5 Replies

Add the reference to the mainform to the uses clause of the implementation section.

Very simple. In the main form, you give a link to the second module. In the main module creates an event handler by pressing a button and write code like this (in the second module does not need links to the main module):

unit MainForm;

..........


uses
  SecondForm;

TMainForm.Button1Clicck(Sender: TObject);
begin
   with TSecondForm.Create(Self) do
   try
     if ShowModal = mrOK then
        MyProcedure(ParamA,ParamB);
   finally
     Free;
   end;
end;

ParamA следует понимать как SecondForm.ParamA

Very simple. In the main form, you give a link to the second module. In the main module creates an event handler by pressing a button and write code like this (in the second module does not need links to the main module):

unit MainForm;

..........


uses
  SecondForm;

TMainForm.Button1Clicck(Sender: TObject);
begin
   with TSecondForm.Create(Self) do
   try
     if ShowModal = mrOK then
        MyProcedure(ParamA,ParamB);
   finally
     Free;
   end;
end;

thanks, this seems to work in calling the dialog, but now i get an error saying that a panel in the dialog 'already exists'. here is my code:

procedure TNeuralNetworkInterface.Button2Click(Sender: TObject);
begin
  with OKRightDlg.Create(nil) do
   try
     if Execute() then
     begin
        NN.createNetwork(OKRightDlg.NrOfInput,OKRightDlg.NrOfOutput,OKRightDlg.useHidden);
     end;
   finally
     Free;
   end;
end;

where OKRightDlg.execute returns (ShowModal = mrOK)

removing the panel in the dialog simply moves the error to the next element (a label). any ideas?

Yes, I forgot to say that this method should be used when dynamically creating dialogues. This will save memory, because memory will be allocated and freed as needed. What would it work to remove the line to automatically create a form. This can be done from the menu in two ways:
1. Open Project -> View source and remove Application.CreateForm(TOKRightDlg, OKRightDlg);
2. Open Project -> Options -> Forms and move TOKRightDlg from Auto-create form to Available form

This requires some programming experience. Therefore recommend that you do not do this, let the form is automatically created. Just a little change code:

procedure TNeuralNetworkInterface.Button2Click(Sender: TObject);
begin
  with OKRightDlg do
     if Execute() then
     begin
        NN.createNetwork(OKRightDlg.NrOfInput,OKRightDlg.NrOfOutput,OKRightDlg.useHidden);
     end;
end;

Dynamic creation of forms related to professional programming. This greatly saves memory when the program lots of dialogue. It is also not very good to automatically create dialogues that are rarely used. Eg "About".
This is a good style. But beware! If you forget to free memory, then get a leak! Program during the work will always spend more and more memory. Windows did not like, the computer begins to slow down.

You can do this:

OKRightDlg := TOKRightDlg.Create(self);
OKRightDlg.DoSometing();
OKRightDlg.Free;

However, it is dangerous. If the method DoSometing an exception is thrown, then the method is not called Free and you get a memory leak.
Use this:

OKRightDlg := TOKRightDlg.Create(self);
try
 OKRightDlg.DoSometing();
finally
 OKRightDlg.Free;
end;

thank you so much, solved the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.