unit SystemStrLCat;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: SystemStrLCat
// Routine: SysUtils.StrLen
// Routine: SysUtils.StrLCat

// BeginCode
{
The following example uses an edit control and a button on a
form in an application. When the button is clicked, the edit
control’s text is split in halves that are copied into
separate buffers. Then the contents of the buffers are
displayed in a message box.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  FirstHalf: PChar;
  SecondHalf: PChar;
  HalfLen: Integer;
begin
  HalfLen := StrLen(PChar(string(Edit1.Text))) div 2;
  GetMem(FirstHalf,HalfLen+2);
  GetMem(SecondHalf,HalfLen+2);
  FirstHalf^ := Chr(0);
  SecondHalf^ := Chr(0);
  StrLCat(FirstHalf, PChar(string(Edit1.Text)), HalfLen);
  StrCat(SecondHalf, PChar(string(Edit1.Text)) + HalfLen);
//  Application.MessageBox(FirstHalf, 'First Half', [smbOK], smsInformation, smbOK, smbCancel);
  Application.MessageBox(FirstHalf, 'First Half', MB_OKCANCEL);
  Application.MessageBox(SecondHalf, 'Second Half', MB_OKCANCEL);
  FreeMem(FirstHalf);
  FreeMem(SecondHalf);
end;
// EndCode
// EndExample: SystemStrLCat
end.
