Forum > General

How to put controls taken from mysql on form?

<< < (3/3)

garlar27:
OOPS!!! I MISSED SOMETHING!!! :-[ :-[ :-[

I didn't assigned the Label's parent!!! Also I forgot to set labels values so you can see them... :-[

The code should be like this:

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

   Label1.Parent := MyForm; // This is what you need to do to make controls visible in the form
   Label2.Parent := MyForm; // This is what you need to do to make controls visible in the form

   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 := 20; // this gives a 20 pixels margin from anchor.

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

   Label1.Caption := 'Hello world!!';
   Label2.Caption := 'This Label2';

   MyForm.ShowModal;
finally
   MyForm.Free;
end;
--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version