其他分享
首页 > 其他分享> > SysUtils.StrCat

SysUtils.StrCat

作者:互联网

SysUtils.StrCat

//把源串添加到目标串后, 要求目标串必须有足够的空间
StrCat(
  Dest: PChar;        {目标串}
  const Source: PChar {源串}
): PChar;             {返回目标串}
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}

//测试 1:
procedure TForm1.Button1Click(Sender: TObject);
var
  p1,p2,p3: PChar;
begin
  p1 := 'abc';
  p2 := '123';

  GetMem(p3, Length(p1) + Length(p2));
  
  StrCat(p3,p1);  
  StrCat(p3,p2);

  ShowMessage(p3); {abc123}

  FreeMem(p3);
end;

//测试 2:
procedure TForm1.Button2Click(Sender: TObject);
var
  arr: array[0..20] of Char;
  pc: PChar;
begin
  arr := 'Embarcadero';
  pc := StrCat(@arr, ' Delphi'); 
   
  ShowMessage(PChar(@arr)); {显示: Embarcadero Delphi}
  ShowMessage(pc);          {显示: Embarcadero Delphi}
end;

end.
SysUtils 单元下的公用函数目录

posted on 2008-05-12 14:11  万一  阅读(2920)  评论(5)  编辑  收藏

标签:p3,arr,PChar,StrCat,TObject,SysUtils
来源: https://blog.51cto.com/u_14617575/2746270