Delphi 2009 Tstringbuilder class [6]: Equals

Source: Internet
Author: User
Tags tostring

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.equals determine if the object is the same

procedure TForm1.Button1Click(Sender: TObject);
var
 sb1,sb2: TStringBuilder;
 b: Boolean;
begin
 sb1 := TStringBuilder.Create('abc');
 sb2 := TStringBuilder.Create('abc');
 b := sb1.Equals(sb2);
 ShowMessage(BoolToStr(b, True)); {True}
 sb2.Length := 0;
 b := sb1.Equals(sb2);
 ShowMessage(BoolToStr(b, True)); {False}
 sb1.Free;
 sb2.Free;
end;

The SB2 in this case did not produce a new object, just pointing to the SB1

procedure TForm1.Button2Click(Sender: TObject);
var
 sb1,sb2: TStringBuilder;
begin
 sb1 := TStringBuilder.Create('abc');
 sb2 := sb1;
 sb1.Append('123');
 ShowMessage(sb2.ToString); {abc123}
 sb2 := sb1.Replace('123', ' 123');
 ShowMessage(sb1.ToString); {abc 123}
 ShowMessage(sb2.ToString); {abc 123}
 ShowMessage(BoolToStr(sb2.Equals(sb1), True)); {True}
 sb1.Free;
end;
end.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.