Copying a string list can have the effect of appending to or overwriting an existing string list. This VCL application appends to a string list. With a simple change, it can overwrite a string list. Creating this VCL application consists of the following steps:
New
Other
Delphi Projects or C++Builder Projects and double-click the VCL Forms Application icon. The VCL Forms Designer is displayed.
var
StringList: TStrings;For C++, enter the following variable declarations:
TStrings *StringList;
StringList := TStringList.Create; try with StringList do begin Add('This example uses a string List.'); Add('It is the easiest way to add strings'); Add('to a combobox''s list of strings.'); Add('Always remember: the TStrings.Create'); Add('method is abstract; use the'); Add('TStringList.Create method instead.'); end; with ComboBox1 do begin Width := 210; Items.Assign(StringList); ItemIndex := 0; end; finally StringList.free; end;
StringList = new TStringList(); try { StringList->Add( "This example uses a string list" ); StringList->Add( "It is the easiest way to add strings" ); StringList->Add( "to a ComboBox's list of strings." ); StringList->Add( "Remember to call the TStringList constructor!" ); ComboBox1->Width = 210; ComboBox1->Items->Assign( StringList ); ComboBox1->ItemIndex = 0; } __finally { StringList->Free(); }
Memo1.Lines.AddStrings(ComboBox1.Items);
Memo1–>Lines->AddStrings( ComboBox1–>Items
Run to build and run the application. The form displays with the controls. Memo1.Lines.Assign(ComboBox1.Items);
Memo1–>Lines->Assign( ComboBox1–>Items );
The strings from ComboBox1 overwrite the 'Memo1' string.
|
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
|
What do you think about this topic? Send feedback!
|