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 xe5 将Delphi code从winos 迁移到ios与android

Delphi mscomm 发送接收

Delphi 判断dll动态链接库是否可用

Delphi获取当前计算机所有盘符

Delphi 中打开浏览器跳转网址链接网页的几种方法

Delphi tfilestream 流操作2

Delphi removeinvalid截取字符串某个字符前面的字符

Delphi stream对象

Delphi fastreport 直接列印

Delphi image1 图像复制到剪切板

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



打赏

取消

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

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

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

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

评论

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