RAD Studio 10.2.3 测试√
var
G_StrList: TStringList;
procedure TForm1.FormCreate(Sender: TObject);
begin
G_StrList := TStringList.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
G_StrList.Free;
end;
// 显示
procedure TForm1.Button_ListShowClick(Sender: TObject);
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(G_StrList);
end;
// 添加
procedure TForm1.Button_ListAddClick(Sender: TObject);
begin
G_StrList.Add(Edit_Content.Text);
Button_ListShow.Click;
end;
// 插入
procedure TForm1.Button_ListInsertClick(Sender: TObject);
begin
G_StrList.Insert(0, Edit_Content.Text);
Button_ListShow.Click;
end;
// 删除【根据序号,写死的删0号下标】
procedure TForm1.Button_ListDelClick(Sender: TObject);
begin
G_StrList.Delete(0);
Button_ListShow.Click;
end;
// 查找
procedure TForm1.Button_ListFindClick(Sender: TObject);
var
mIndex: Integer;
begin
mIndex := G_StrList.IndexOf(Edit_Content.Text);
ShowMessage(IntToStr(mIndex));
end;
// 排序
procedure TForm1.Button_ListSortClick(Sender: TObject);
begin
G_StrList.Sort;
Button_ListShow.Click;
end;
// 排序反转
procedure TForm1.Button_ListReverseClick(Sender: TObject);
var
i, mCount: Integer;
mTempStr: string;
begin
mCount := G_StrList.Count - 1;
for i := 0 to mCount do
begin
if i >= (mCount - i) then
Break;
mTempStr := G_StrList[mCount - i];
G_StrList[mCount - i] := G_StrList[i];
G_StrList[i] := mTempStr;
end;
Button_ListShow.Click;
end;
// 清空
procedure TForm1.Button_ListClearClick(Sender: TObject);
begin
G_StrList.Clear;
Button_ListShow.Click;
end;
一点点笔记,以便以后翻阅。