Delphi memo1 行倒序排列三种方法


本文整理自网络,侵删。

 
来源:http://www.xuexidashi.vip

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo3: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  T1, T2: Integer;
begin
  if Memo1.Text <> '' then
  begin
    T1 := GetTickCount;
    Memo2.Clear;
    for I := Memo1.Lines.Count - 1 downto 0 do
      Memo2.Lines.Add(Memo1.Lines[I]);
    T2 := GetTickCount;
    Memo3.Lines.Add('第一种用时:' + IntToStr(T2 - T1));
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  I: Integer;
  T1, T2: Integer;
begin
  if Memo1.Text <> '' then
  begin
    T1 := GetTickCount;
    Memo2.Lines.BeginUpdate;
    Memo2.Clear;
    for I := Memo1.Lines.Count - 1 downto 0 do
      Memo2.Lines.Add(Memo1.Lines[I]);
    Memo2.Lines.EndUpdate;
    T2 := GetTickCount;
    Memo3.Lines.Add('第二种用时:' + IntToStr(T2 - T1));
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  I: Integer;
  T1, T2: Integer;
  SList: TStringList;
begin
  if Memo1.Text <> '' then
  begin
    T1 := GetTickCount;
    SList := TStringList.Create;
    try
      for I := Memo1.Lines.Count - 1 downto 0 do
        SList.Add(Memo1.Lines[I]);
      Memo2.Lines.BeginUpdate;
      Memo2.Clear;
      Memo2.Lines.Text := SList.Text;
      Memo2.Lines.EndUpdate;
    finally
      SList.Free;
    end;
    T2 := GetTickCount;
    Memo3.Lines.Add('第三种用时:' + IntToStr(T2 - T1));
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo3.Clear;
  Memo3.Lines.Add('共有行数:' + IntToStr(Memo1.Lines.Count));
end;

end.

相关阅读 >>

Delphi idftp

Delphi 拷贝文件夹内所有内容

Delphi 搜索字符串在流中的位置

Delphi encddecd 加密解密

Delphi winapi: settimer、killtimer - 创建与移除高性能定时器

Delphi idtcpclient1实现端口扫描器

Delphi 使用 idhttp 获取 utf-8 编码的中文网页

Delphi 在richedit中插入gif图片的方法

Delphi做繁体简体转换

Delphi xe7 ios 取得系统字型名称

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



打赏

取消

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

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

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

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

评论

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