unit main;

{$mode objfpc}{$H+}

{ $DEFINE DEBUG}
  //{$UNDEF debug}
interface

uses SysUtils, Forms, StdCtrls, dbugintf, LazLogger, dialogs, Classes;

type

    { TForm1 }

    TForm1 = class(TForm)
      Edit1: TEdit;
      Label1: TLabel;
      procedure Edit1Change(Sender: TObject);
    private
      function InvertirCadena(const s: string): string;
    end;

var
Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Edit1Change(Sender: TObject);
begin
Label1.Caption:= InvertirCadena(Edit1.Text);
end;

{function TForm1.InvertirCadena(const s: string): string;
var
long, p: integer;
begin
SendMethodEnter('InvertirCadena');
long:= Length(s);
SetLength(Result, long);
for p in [1..long] do
Result[long + 1 - p] := s[p];
SendDebugFmt('El resultado es "%s"',[Result]);
end;  }
{function TForm1.InvertirCadena(const s: string): string; var long, p: integer;
begin
  {$IFDEF debug}

DebugLnEnter('Parametro recibido "%s"',[s]);   {$ENDIF}

long:= Length(s);

SetLength(Result, long);

for p in [1..long] do

begin
{$IFDEF debug}
DebugLn(['longitud: ',long,'; p: ',p,'; longitud - p: ',long-p]);
{$ENDIF}
Result[long + 1 - p] := s[p];
end;
{$IFDEF debug}
DebugLnExit('Saliendo de InvertirCadena, valor final de p %d',[p]);
{$ENDIF}
end;   }

function TForm1.InvertirCadena(const s: string): string;
var long, p: integer;
begin
	long:= Length(s);
	SetLength(Result, long);
	for p in [1..long] do
            Result[long - p+1] := s[p];
end;

end.
