SysUtils.StrCat

SysUtils.StrCat
//把源串添加到目标串后, 要求目标串必须有足够的空间
StrCat(
  Dest: PChar;        {目标串}
  const Source: PChar {源串}
): PChar;             {返回目标串}

//测试 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); 
  //StrCopy(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';
  //StrCopy(@arr, 'Embarcadero'); {可以代替上一句}
  pc := StrCat(@arr, ' Delphi');
  
  ShowMessage(PChar(@arr)); {显示: Embarcadero Delphi}
  ShowMessage(pc);          {显示: Embarcadero Delphi}
end;

你可能感兴趣的:(util)