//把源串添加到目标串后, 要求目标串必须有足够的空间
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 单元下的公用函数目录