Einzelnen Beitrag anzeigen

busybyte

Registriert seit: 15. Sep 2006
165 Beiträge
 
#6

Re: Per Befehl Checkbox erstellen

  Alt 17. Feb 2008, 14:33
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;



  Type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
  mycb:Array of TCheckbox;
  procedure mycbClick(Sender: TObject);
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Procedure freeall;
Var L1,cnt1:integer;
begin
L1:=Length(Form1.mycb);
for cnt1 := 0 to L1 - 1 do
freeandnil(Form1.mycb[cnt1]);
end;

Procedure TForm1.mycbclick(Sender: TObject);
begin
 with TCheckbox(Sender) do
  begin
  showmessage(Name+' Clicked!');
   if checked then caption:='checked'
   else caption:='unchecked';
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
Var L1:integer;
begin
L1:=Length(mycb);
Setlength(mycb,L1+1);

mycb[L1]:=TCheckbox.create(Form1);
try
 with mycb[L1] do
  begin
  Parent:=Form1;
  Caption:='MyCheckbox';
  Left:=10;
  Top:=L1*30+10;
  Name:='MyCb'+inttostr(L1+1);
  OnClick:=mycbClick;
  end;
except freeall; end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
freeall;
end;

end.
  Mit Zitat antworten Zitat