SystemStrLCat (Object Pascal)

From Appmethod Code Examples
Jump to: navigation, search

Description

The following example uses an edit control and a button on a form in an application. When the button is clicked, the text in the edit control is split in halves that are copied into separate buffers. Then the contents of the buffers are displayed in a message box.

Code

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;

Uses