delphi Memo1 行随机打乱


本文整理自网络,侵删。

 
procedure ShuffleStrings(List: TStrings; MoveCount: Integer = 0);

var

i, N, C: Integer;

Index1, Index2: Integer;

Str: string;

Obj: TObject;

begin

List.BeginUpdate;

try

C:=List.Count;

N:=MoveCount;

if N <= 0 then N:=C*C-C;

for i:=0 to N do begin

  Index1:=Random(C);

  Index2:=Random(C);

  Str:=List.Strings[Index1];

  Obj:=List.Objects[Index1];

  List.Strings[Index1]:=List.Strings[Index2];

  List.Objects[Index1]:=List.Objects[Index2];

  List.Strings[Index2]:=Str;

  List.Objects[Index2]:=Obj;

end;

finally

List.EndUpdate;

end;

end;


procedure TForm1.Button1Click(Sender: TObject);
begin
ShuffleStrings(Memo1.Lines);
end;

相关阅读 >>

Delphi 创建console-控制台应用

Delphi inttohex 查看字符的十六进制值

Delphi编写dll(以及静态和动态方式调用)

Delphi ntfs usn 磁盘文件搜索

Delphi listview 导出excel txt vcf 单元

Delphi firedac 下的 sqlite [4] - 创建数据库

Delphi 内存修改的实现

Delphi读取android短信信息

Delphi 调用dos nbtstat 并获得结果

Delphi sqlite incomplete input 错误

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...