unit SystemStrEnd;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: SystemStrEnd
// Routine: SysUtils.StrEnd

// BeginCode
{
The following example uses an edit control, a label, and a
button on a form. When the button is clicked, the edit
control’s text is copied into a buffer. Then the buffer is
displayed backwards in the label.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  TextBuffer: PChar;
  Ptr: PChar;
begin
  GetMem(TextBuffer, Length(Edit1.Text)+1);
  StrCopy(TextBuffer, PChar(Edit1.Text));
  Ptr := StrEnd(TextBuffer);
  Label1.Caption := '';
  while Ptr > TextBuffer do
  begin
    Dec(Ptr);
    Label1.Caption := Label1.Caption + Ptr^;
  end;
  FreeMem(TextBuffer);
end;
// EndCode
// EndExample: SystemStrEnd
end.
