Quantcast
Channel: Delphi Forum - Delphi Programming Kings of Code - Delphi Programming
Viewing all articles
Browse latest Browse all 173

string for Tobject

$
0
0
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;

 

Viewing all articles
Browse latest Browse all 173

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>