2009年5月29日

Delphi 的 TStrings

Delphi 的很多元件中都有 TStrings 的存在
在 Form 上放入 TValueListEditor, TMemo, TListBox, TComboBox, TRadioGroup, TCheckListBox, TListView, TQuery

uses
Printers;

在 Form Create 事件中加入

procedure TForm1.FormCreate(Sender: TObject);
begin
// ValueListEditor1.Strings 為 TStrings 子類別
with ValueListEditor1 do
begin
Values['TW'] := '臺灣'; // TW=臺灣
Values['CN'] := '中國'; // CN=中國
Strings.AddStrings(Printer.Printers); // 加列出印表機
// Printer.Printers 為 TStrings 子類別
Memo1.Lines := Strings; //
ListBox1.Items := Strings; //
RadioGroup1.Items := Strings; //
CheckListBox1.Items := Strings; //
ComboBox1.Items := Strings; //
ComboBox1.ItemIndex := 0;

Query1.SQL := Strings; // 測試用 Query1.SQL 也是 TStrings 子類別

with ListView1 do
begin
ViewStyle := vsReport;
Columns.Add.Caption := 'Caption';
Columns.Add.Caption := 'A';
Columns.Add.Caption := 'B';
with ListView1.Items.Add do
begin
Caption := '1';
SubItems := Strings; //
end;
end;
end;
end;

執行程式後除了 Query1 是不可見外,其它元件可以看到

沒有留言:

網誌存檔