Forum > General

How to put controls taken from mysql on form?

<< < (2/3) > >>

typo:
To create them dinamically you need to use the constructor Create and set the Owner properly as parameter of the constructor. This ensures them to be freed once the Owner is freed.

garlar27:
What typo said here is the safer option:

--- Quote from: typo on December 17, 2010, 02:50:19 pm ---If I was you I would design the whole form at desing time and set Visible True or False to the controls.

--- End quote ---

He also explained how it works here:

--- Quote from: typo on December 17, 2010, 03:19:32 pm ---To create them dinamically you need to use the constructor Create and set the Owner properly as parameter of the constructor. This ensures them to be freed once the Owner is freed.

--- End quote ---

the three functions are 3 ways to do the same thing. Personally I like the second one you can use it as it where a procedure or catch the result to do and special config.

Let me give you some advice about creating "disposable" components in a form:

If you are going to use disposable components in a form it is better that the form which you use to create and show the components, should also be disposable.

Maybe an example would help to explain my point:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure RunDisposableForm;var   Form: TForm;begin   Form := TForm.Create(nil{ this is important so your form won't remain in memmory until you close the main program });   try      { create your components }      Form.ShowModal;       { process the data obtained from the form }   finally      Form.Free; { YOU HAVE TO RELEASE THE MEMMORY THAT YOU DONT NEED ANY MORE!!!}   end;end; 
remember to pay attention to what are you doing because you're walking on thin ice  :o

krexon:
Thanks for all your ideas :)
I think I will try with putting controls at design time and hiding not used with selected customer. To avoid a lot of empty spaces between controls, I thought of using variable t:=t+20 which represents top position of TEdit, TDateTime, t:=t+110 for TMemo.

garlar27:
You can use anchors to help you fit and organize your controls inside the form. It's a little tricky to set anchors from code, but not impossible.

The following code creates a Form and 2 Labels and anchor a Label1 to the top left of a form and Label2 is anchored to the Top Right of Label1:

--- Code: ---MyForm := TFotm.Create(nil);
try
   Label1 := TLabel.Create(MyForm);
   Label2 := TLabel.Create(MyForm);

   Label1 := MyForm;
   Label2 := MyForm;

   Label1.AutoSize    := TRUE;
   Label1.ParentFont  := TRUE;
   Label1.Transparent := TRUE;
   Label1.Top  := 0;
   Label1.Left := 0;

   Label1.AnchorSide[akLeft].Side := asrLeft;
   Label1.AnchorSide[akLeft].Control := MyForm;
   Label1.BorderSpacing.Left := 0;

   Label1.AnchorSide[akTop].Side := asrTop;
   Label1.AnchorSide[akTop].Control := MyForm;
   Label1.BorderSpacing.Top := 0;

   Label1.AnchorSide[akBottom].Side := asrBottom;
   Label1.AnchorSide[akBottom].Control := Self;
   Label1.BorderSpacing.Bottom := 0;


   Label2.AutoSize    := TRUE;
   Label2.ParentFont  := FALSE;
   Label2.Transparent := TRUE;

   Label2.AnchorSide[akLeft].Side := asrRight;
   Label2.AnchorSide[akLeft].Control := Label1;
   Label2.BorderSpacing.Left := 0;

   Label2.AnchorSide[akTop].Side := asrTop;
   Label2.AnchorSide[akTop].Control := Label1;
   Label2.BorderSpacing.Top := 0;

   MyForm.ShowModal;
finally
   MyForm.Free;
end;

--- End code ---

I hope you can take some ideas from that (if this is what you need) ...

krexon:
Thanks, I will try :)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version