Jump to content

Recreating a dynamically created form


artem_niko

Recommended Posts

Good afternoon!
I solve this problem: I need to create a form dynamically and load my frame on it, and if the form already exists, then close it (destroy it), along with all the contents, and create it again with a frame. Simply put, recreate an already existing and previously created dynamically form. Everything should be done with one button.

Here is the form creation code that creates the form dynamically initially:

TestForm:=TUniForm.Create(UniApplication);
TestForm.Height:=500;
TestForm.Width:=500;
TestForm.Parent:=MainForm;
TestForm.Name:='test';
TestForm.BorderIcons:=[biSystemMenu,biMaximize];
TestForm.BorderStyle:=bsSizeable;
TestForm.Caption:='test';
TestForm.Show;

Before the form creation code, I tried to add such a code to search for and delete a previously created form:

for i:=Screen.FormCount-1 downto 0 do
begin
  if Screen.Forms[i].Name = 'test' then
     Screen.Forms[i].Free;
end;

The first time the form is created:

image.png.7a45e939a97b3924815ceff3ca9c28a5.png

 

Without closing this form, I try to recreate it, but I get an error:

image.png.c0a32fa68247a4f945b50ed7e050c0bc.png

 

I ask for help in solving my problem

Initially, I thought that maybe you can create an empty form in the usual way and use it already for my frames, because I need to upload different frames to separate instances of the form, but it seems to me that this will not work...

Link to comment
Share on other sites

8 hours ago, artem_niko said:

Good afternoon!
I solve this problem: I need to create a form dynamically and load my frame on it, and if the form already exists, then close it (destroy it), along with all the contents, and create it again with a frame. Simply put, recreate an already existing and previously created dynamically form. Everything should be done with one button.

Here is the form creation code that creates the form dynamically initially:

TestForm:=TUniForm.Create(UniApplication);
TestForm.Height:=500;
TestForm.Width:=500;
TestForm.Parent:=MainForm;
TestForm.Name:='test';
TestForm.BorderIcons:=[biSystemMenu,biMaximize];
TestForm.BorderStyle:=bsSizeable;
TestForm.Caption:='test';
TestForm.Show;

Before the form creation code, I tried to add such a code to search for and delete a previously created form:

for i:=Screen.FormCount-1 downto 0 do
begin
  if Screen.Forms[i].Name = 'test' then
     Screen.Forms[i].Free;
end;

The first time the form is created:

image.png.7a45e939a97b3924815ceff3ca9c28a5.png

 

Without closing this form, I try to recreate it, but I get an error:

image.png.c0a32fa68247a4f945b50ed7e050c0bc.png

 

I ask for help in solving my problem

Initially, I thought that maybe you can create an empty form in the usual way and use it already for my frames, because I need to upload different frames to separate instances of the form, but it seems to me that this will not work...

In general, I figured out my question myself and it's not relevant.
But, I have another question.

Is it possible to make the created form on top of windows, for example, so that I can move it around the screen outside of the main application?
For example, let's say I have 2 monitors on one computer. I want to run the project on one monitor, and move the created form to the second monitor.

Is it possible to do this?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...