unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst;
type
tmyclass=class
private
Ftext: string;
procedure Settext(const Value: string);
public
property text:string read Ftext write Settext;
end;
type
TForm1 = class(TForm)
CheckListBox1: TCheckListBox;
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CheckListBox1ClickCheck(Sender: TObject);
private
public
end;
var
Form1: TForm1;
list:tstringlist;
implementation
{$R *.dfm}
procedure tmyclass.Settext(const Value: string);
begin
Ftext := Value;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
mc:tmyclass;
begin
list:=tstringlist.Create;
mc:=tmyclass.create;
mc.text:='Тестовая строка 1';
list.Addobject(mc.text,pointer(mc));
mc:=tmyclass.create;
mc.text:='Тестовая строка 2';
list.Addobject(mc.text,pointer(mc));
mc:=tmyclass.create;
mc.text:='Тестовая строка 3';
list.Addobject(mc.text,pointer(mc));
checklistbox1.Items.Assign(list);
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i:integer;
begin
if assigned(list) then
begin
for i:=0 to list.Count-1 do
list.Objects[i].Free;
list.destroy;
end;
end;
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
var
lst:tstrings;
i:integer;
begin
i:=checklistbox1.ItemIndex;
if checklistbox1.Checked[i] then
begin
if checklistbox1.items.objects[i] is tmyclass then
memo1.Lines.Add(tmyclass(checklistbox1.items.objects[i]).text);
end;
end;
end.