procedure TForm1.FormCreate(Sender: TObject);var MyList: TStringList; i,Index: Integer; begin MyList := TStringList.Create; try MyList.Add('edit1.text'); for i:=0 to combobox1.Items.Count-1 do MyList.Addcombobox1.Items[i]); MyList.Add(memo1.text); MyList.Sort; { Find will only work on sorted lists! } if MyList.Find('Flowers', Index) then begin ListBox1.Items.AddStrings(MyList); Label1.Caption := 'Flowers has an index value of ' + IntToStr(Index); end; finally MyList.Free; end; end;
procedure TForm1.ClearText(AControl:TWinControl); var I: Integer; begin for I := 0 to AControl.ControlCount - 1 do // Iterate begin // MyList 上面创建的,其余的类似 if AControl.Controls[i] is TEdit then begin MyList.Add((AControl.Controls[i] as TEdit).Text); end; if AControl.Controls[i] is TPanel then begin ClearText(AControl.Controls[i] as TPanel); end; end; end; procedure TForm1.btn1Click(Sender: TObject); begin ClearText(self); end;
MyList: TStringList;
i,Index: Integer;
begin
MyList := TStringList.Create;
try
MyList.Add('edit1.text');
for i:=0 to combobox1.Items.Count-1 do
MyList.Addcombobox1.Items[i]); MyList.Add(memo1.text); MyList.Sort; { Find will only work on sorted lists! }
if MyList.Find('Flowers', Index) then
begin
ListBox1.Items.AddStrings(MyList);
Label1.Caption := 'Flowers has an index value of ' + IntToStr(Index);
end;
finally
MyList.Free;
end;
end;
var
I: Integer;
begin
for I := 0 to AControl.ControlCount - 1 do // Iterate
begin
// MyList 上面创建的,其余的类似
if AControl.Controls[i] is TEdit then
begin
MyList.Add((AControl.Controls[i] as TEdit).Text);
end;
if AControl.Controls[i] is TPanel then
begin
ClearText(AControl.Controls[i] as TPanel);
end;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
ClearText(self);
end;