//如果正确,就给分吧
//unit
unit umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
C_Caption = 'MergeStr';
type
TfrmMergeStr = class(TForm)
btnGetMerge: TButton;
edStr: TEdit;
mmList: TMemo;
procedure btnGetMergeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
procedure Ms(const str: string);
function push(const s: string): boolean;
function pop(var s: string): boolean;
{ Public declarations }
end;
var
frmMergeStr: TfrmMergeStr;
ol, rs: TStrings;
implementation
{$R *.dfm}
procedure TfrmMergeStr.btnGetMergeClick(Sender: TObject);
var
ist: integer;
begin
if (edstr.Text = '') then exit;
mmList.Clear;
ist := GetTickCount;
Ms(edstr.Text);
mmList.Lines.AddStrings(rs);
Caption := format('%s (%d) time(%d)',
[C_Caption, mmList.Lines.Count, GetTickCount - ist]);
end;
procedure TfrmMergeStr.FormCreate(Sender: TObject);
begin
ol := TStringList.Create;
rs := TStringList.Create;
Caption := C_Caption;
end;
procedure TfrmMergeStr.FormDestroy(Sender: TObject);
begin
FreeAndNil(ol);
FreeAndNil(rs);
end;
procedure TfrmMergeStr.Ms(const str: string);
var
i, len: integer;
s: string;
begin
len := length(str);
for i := 1 to Len do begin
push(str);
end;
while (pop(s)) do
begin
//mmList.Lines.Add(s);
Application.ProcessMessages;
rs.Add(s);
if (Length(s) < len) then
begin
for i := 1 to len do
begin
push(format('%s%s', [s, str]));
end;
end;
end;
end;
function TfrmMergeStr.pop(var s: string): boolean;
begin
result := ol.Count > 0;
if result then
begin
s := ol[0];
ol.Delete(0);
end;
end;
function TfrmMergeStr.push(const s: string): boolean;
begin
ol.Insert(0, s);
result := true;
end;
end.
//dfm
object frmMergeStr: TfrmMergeStr
Left = 192
Top = 133
Width = 378
Height = 340
Caption = 'MergeStr'
Color = clBtnFace
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Scaled = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 14
object btnGetMerge: TButton
Left = 32
Top = 48
Width = 75
Height = 25
Caption = 'GetMerge'
TabOrder = 1
OnClick = btnGetMergeClick
end
object edStr: TEdit
Left = 32
Top = 16
Width = 121
Height = 22
TabOrder = 0
end
object mmList: TMemo
Left = 184
Top = 16
Width = 169
Height = 281
ScrollBars = ssVertical
TabOrder = 2
end
end