type
TString = class(TObject)
private
fStr: String;
public
constructor Create(const VStr: String);
property Str: String read FStr write FStr;
end;
{...}
constructor TString.Create(const VStr: String);
begin
inherited Create;
FStr:= VStr;
end;
Example
------------------------
<ComboBox>.Items.AddObject('Example',TString.Create('ABCDEF'));
------------------------
procedure TForm1.<ComboBox>Change(Sender: TObject);
begin
if <ComboBox>.Text<>EmptyStr then
begin
Edit1.Text:= TString(<ComboBox>.Items.Objects[<ComboBox>.ItemIndex]).Str;
end;
end;
Important: Memory Leak Solution
-------------------------------
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
I:Integer;
begin
for I := 0 to <ComboBox>.Count -1 do
begin
TString(<ComboBox>.Items.Objects).Str:='';
TString(<ComboBox>.Items.Objects).Free;
end;
TString = class(TObject)
private
fStr: String;
public
constructor Create(const VStr: String);
property Str: String read FStr write FStr;
end;
{...}
constructor TString.Create(const VStr: String);
begin
inherited Create;
FStr:= VStr;
end;
Example
------------------------
<ComboBox>.Items.AddObject('Example',TString.Create('ABCDEF'));
------------------------
procedure TForm1.<ComboBox>Change(Sender: TObject);
begin
if <ComboBox>.Text<>EmptyStr then
begin
Edit1.Text:= TString(<ComboBox>.Items.Objects[<ComboBox>.ItemIndex]).Str;
end;
end;
Important: Memory Leak Solution
-------------------------------
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
I:Integer;
begin
for I := 0 to <ComboBox>.Count -1 do
begin
TString(<ComboBox>.Items.Objects).Str:='';
TString(<ComboBox>.Items.Objects).Free;
end;