Delphi 2009之TStringBuilder类[1]: Create

unit Unit1;

interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;
type
 TForm1 = class(TForm)
  Button1: TButton;
  Button2: TButton;
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
 end;

var

 Form1: TForm1;
implementation
{$R *.dfm}

//TStringBuilder.Create 可以无参数

procedure TForm1.Button1Click(Sender: TObject);
var
 sb: TStringBuilder;
begin
 sb := TStringBuilder.Create;
 sb.Append('Embarcadero');
 sb.Append(' CodeGear');
 sb.Append(' Delphi');
 sb.Append(' 2009');
 ShowMessage(sb.ToString); {Embarcadero CodeGear Delphi 2009}
 sb.Free;
end;

//TStringBuilder.Create 可用字符串初始化; 其他重载用处不大

procedure TForm1.Button2Click(Sender: TObject);
var
 sb: TStringBuilder;
begin
 sb := TStringBuilder.Create('Delphi ');
 sb.Append(2009);
 ShowMessage(sb.ToString); {Delphi 2009}
 sb.Free;
end;

end.

时间: 2024-09-25 15:42:46

Delphi 2009之TStringBuilder类[1]: Create的相关文章

Delphi 2009之TStringBuilder类[5]: Chars[]属性与CopyTo方法

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Se

Delphi 2009之TStringBuilder类[4]: Insert与Remove

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R

Delphi 2009之TStringBuilder类[3]: Replace

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender:

Delphi 2009之TStringBuilder类[2]: Append与AppendFormat

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; procedure Bu

Delphi 2009之TStringBuilder类[7]: ToString

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R

Delphi 2009之TStringBuilder类[6]: Equals

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Se

Delphi 2009中TStrings与TStream的增强

在 Delphi 2009 中, TStrings 类(包括 TStringList 和包含 TStrings 属性的所有组件, 譬如 Memo.lines 属性.ListBox.Items 属性). TStream 类系列(包括 TFileStream.TMemoryStream 等) 的存取方法, 譬如 : LoadFromFile.SaveToFile.LoadFromStream.SaveToStream, 都有了选择 TEncoding 参数的重载. 本例效果图:

Delphi 2009泛型容器单元(Generics.Collections)[4]: TDictionary<T>

TDictionary 类似哈希表. 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Edit1: TEdit; Edit2: TEdit; Button1: TButton; Button2: TB

Delphi 2009泛型容器单元(Generics.Collections)[3]: TStack<T>

TQueue 和 TStack, 一个是队列列表, 一个是堆栈列表; 一个是先进先出, 一个是先进后出. TStack 主要有三个方法.一个属性: Push(压栈).Pop(出栈).Peek(查看下一个要出栈的元素); Count(元素总数). 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdC