unit DemoComboBoxMitObjecte;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TmyClass=
Class(TObject)
private
FEintrag2: Integer;
FEintrag1:
String;
procedure SetEintrag1(
const Value:
String);
procedure SetEintrag2(
const Value: Integer);
public
constructor Create;
destructor Destroy;
override;
property Eintrag1:
String read FEintrag1
write SetEintrag1;
property Eintrag2: Integer
read FEintrag2
write SetEintrag2;
End;
type
TfrmDemoComboBoxMitObject =
class(TForm)
CobMitObject: TComboBox;
edEintrag1: TLabeledEdit;
edEintrag2: TLabeledEdit;
procedure FormCreate(Sender: TObject);
procedure CobMitObjectChange(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
frmDemoComboBoxMitObject: TfrmDemoComboBoxMitObject;
implementation
{$R *.dfm}
{ myClass }
constructor TmyClass.Create;
begin
inherited;
end;
destructor TmyClass.Destroy;
begin
inherited;
end;
procedure TmyClass.SetEintrag1(
const Value:
String);
begin
FEintrag1 := Value;
end;
procedure TmyClass.SetEintrag2(
const Value: Integer);
begin
FEintrag2 := Value;
end;
{ Programm }
procedure TfrmDemoComboBoxMitObject.CobMitObjectChange(Sender: TObject);
begin
edEintrag1.Text:= TmyClass(CobMitObject.Items.Objects[CobMitObject.ItemIndex]).Eintrag1;
edEintrag2.Text:= inttostr(TmyClass(CobMitObject.Items.Objects[CobMitObject.ItemIndex]).Eintrag2);
end;
procedure TfrmDemoComboBoxMitObject.FormCreate(Sender: TObject);
var
oMyObject1: TmyClass;
begin
oMyObject1:= TmyClass.Create;
// Erste Object erzeugen
oMyObject1.Eintrag1:= '
Das ist der erte Eintrag';
oMyObject1.Eintrag2:= 10001;
CobMitObject.Items.AddObject('
Item1',oMyObject1);
oMyObject1:= TmyClass.Create;
// Zweites Object erzeugen
oMyObject1.Eintrag1:= '
Das ist der zweite Eintrag';
oMyObject1.Eintrag2:= 20002;
CobMitObject.Items.AddObject('
Item2',oMyObject1);
CobMitObject.ItemIndex:= 0;
end;
procedure TfrmDemoComboBoxMitObject.FormDestroy(Sender: TObject);
var i: integer;
begin
for i:=CobMitObject.Items.Count -1
downto 0
do
begin
TmyClass(CobMitObject.Items.Objects[i]).Free;
end;
end;
end.