Board index » delphi » Creating visual components during runtime

Creating visual components during runtime

Hello

I need to be able to create TCheckBoxes during runtime. Is this possible,
and if so, how do I do it? I'm using Delphi 3.
Thanks in advance.

Jim.

 

Re:Creating visual components during runtime


Quote
"Jim Wink" <wink_...@si.com> wrote in message

news:90l2v3$t3d5@bornews.inprise.com...

Quote
> Hello

> I need to be able to create TCheckBoxes during runtime. Is this possible,
> and if so, how do I do it? I'm using Delphi 3.
> Thanks in advance.

var
  cb: TCheckBox;
begin
  cb := TCheckBox.Create(Self);
  cb.Parent := Self;
  cb.Top := 100;
  cb.Left := 100;
  cb.Height := 17;
  cb.Width := 97;
  cb.Caption := 'TestBox';
end;

set the properties of the CheckBox as desired.

--
Windows 3.1 - The XT Emulator for the 486.
Linux: Because rebooting is for adding new hardware.
ICQ: 91418899
http://www.planeted.co.uk
http://members.nbci.com/edduffe

Re:Creating visual components during runtime


Quote
Jim Wink wrote in message

 <90l2v3$t...@bornews.inprise.com> ...
Quote
>Hello

>I need to be able to create TCheckBoxes during runtime. Is this possible,
>and if so, how do I do it? I'm using Delphi 3.
>Thanks in advance.

    It's looks like this:

type
  Form1 = class(TForm)
  private
    FCheckBox: TCheckBox;
    procedure SomeProc;
  end;

procedure Form1.SomeProc;
begin
  FCheckBox := TCheckBox.Create(Self);
  FCheckBox.Parent := Self;
end;

    Regards, Alex.

Re:Creating visual components during runtime


Quote
On Wed, 6 Dec 2000 10:05:38 -0000, "Jim Wink" <wink_...@si.com> wrote:
>I need to be able to create TCheckBoxes during runtime. Is this possible,
>and if so, how do I do it? I'm using Delphi 3.
>Thanks in advance.

Jim, something like

procedure TSomeForm.SomeEvent(...)
begin
   with TCheckBox.Create(Self) do begin
      Parent:= Self;
      Caption:= 'Dynamic CheckBox';
      OnClick:= OnClickEvent;
   end;
end;

HTH
ain

Re:Creating visual components during runtime


If you want to have several checkboxes and have some control of them you
could put them in an array
using something like this...Works in Delphi 5 anyway...

var
    Form1 : TForm1
    MyCheckBox: Array of TCheckBox;
..
...
{ proc to create iNum of checkboxes }
procedure TForm1.CreateChkBoxes(iNum:Integer);
var
    id : Integer;
begin
    SetLength(MyCheckBox,iNum); // Set the size of our array

{ Loop trough all in array }
    For id := 0 to High(MyCheckBox) do begin
        MyCheckBox[id] := TCheckBox.Create(self);

        With MyCheckBox[id] do begin
            Parent := Self; // required
        { Some other properties of checkbox, not required}
            // U probably want to change the position of the diffrent
checkboxes using top or left....
            Top := 10 * id;
            Tag := Id // Perhaps useful if u want to see who the sender was,
with something like (Sender as TCheckBox).Tag
        end;
    end;
end;

"Jim Wink" <wink_...@si.com> skrev i meddelandet
news:90l2v3$t3d5@bornews.inprise.com...

Quote
> Hello

> I need to be able to create TCheckBoxes during runtime. Is this possible,
> and if so, how do I do it? I'm using Delphi 3.
> Thanks in advance.

> Jim.

Other Threads