var StringList: TStrings; begin 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 TStrings.Create method'); Add('is abstract; So use TStringList.Create'); Add('method instead.'); end; with ComboBox1 do begin Width := 210; Items.Assign(StringList); ItemIndex := 0; end; finally StringList.free; end; end;
另外别忘了最后要把它free掉。currentfields.free();
就是说TStrings是专门让人扩充用的,你也可派生它;
currentfields:Tstrings;begin
currentfields:=tstringlist.create;
query1.GetFieldNames(currentfields);//这行???
currentfields.free;
end;
而是用 currentfields:=tstringlist.create ?currentfields 是 tstring 啊
begin 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 TStrings.Create method');
Add('is abstract; So use TStringList.Create');
Add('method instead.'); end; with ComboBox1 do begin Width := 210;
Items.Assign(StringList);
ItemIndex := 0;
end;
finally
StringList.free;
end;
end;