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 之 对话框组件

Delphi 查看指定文件是否在进程列表中

Delphi isdirectory 判断是否是目录

Delphi提取任意长度随机数

Delphi xe5 为android增加启动图片显示

Delphi让程序运行后自我删除或恢复名称

Delphi for 循环的例子 多种用法

Delphi html document接口获取网页中所有图片

Delphi 常用api 函数

Delphi 全局钩子锁定键盘

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



打赏

取消

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

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

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

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

评论

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