unit MainForm;
interface
uses
  SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
  FMX_Dialogs, FMX_Edit, FMX_Colors, FMX_Objects, FMX_Layouts, FMX_Memo;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Panel1: TPanel;
    StyleBook1: TStyleBook;
    procedure FormResize(Sender: TObject);
    procedure Text1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    procedure Text1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
    procedure Panel1Click(Sender: TObject);
    procedure Text1DblClick(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
      Shift: TShiftState);
    procedure Text1KeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar;
      Shift: TShiftState);
  private
    { Private declarations }
    DragText: TText;
    EditText: TText;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Panel1Click(Sender: TObject);
begin
//if not Edit1.Visible then
  begin
    Edit1.Visible := True;
    Edit1.SetFocus
  end
end;

procedure TForm1.Text1DblClick(Sender: TObject);
begin
  if not (Sender is TText) then Exit; // only for TText

  if not Edit1.Visible then
  begin
    EditText := (Sender as TText);
    EditText.Font.Style := EditText.Font.Style + [TFontStyle.fsUnderline];
    Edit1.Visible := True;
    Edit1.Text := EditText.Text;
    Edit1.SetFocus
  end
end;

procedure TForm1.Text1KeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar;
  Shift: TShiftState);
begin
  if not Edit1.Visible then
  begin
    EditText := (Sender as TText);
    EditText.Font.Style := EditText.Font.Style + [TFontStyle.fsUnderline];
    Edit1.Visible := True;
    Edit1.Text := EditText.Text;
    Edit1.SetFocus
  end
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
var
  NewText: TText;
begin
  if (Key = 13) or (Key = 27) then
  begin
    if Assigned(EditText) then
    begin
      if (Key = 13) then EditText.Text := Edit1.Text;
      Edit1.Visible := False;
      EditText.Font.Style := EditText.Font.Style - [TFontStyle.fsUnderline];
      EditText := nil // Done
    end
    else // new label
    begin
      Edit1.Visible := False;
      if Length(Edit1.Text) > 0 then
      begin
        NewText := TText.Create(Self);
        NewText.Parent := Panel1;
        NewText.Position := Edit1.Position;
        NewText.WordWrap := False;
        NewText.Font.Size := 32;
        NewText.Text := Edit1.Text;
        NewText.AutoSize := True;
        NewText.OnMouseDown := Text1MouseDown;
        NewText.OnMouseUp := Text1MouseUp;
        NewText.OnClick := Text1DblClick;
        NewText.OnKeyDown := Text1KeyDown;
      end
    end
  end
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Edit1.Position.X := ClientWidth - 320 + 112;
  Edit1.Position.Y := 8;
end;

procedure TForm1.Text1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  DragText := Sender as TText
end;

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
begin
  if assigned(DragText) then
  begin
    DragText.Position.X := X;
    DragText.Position.Y := Y
  end
end;

procedure TForm1.Text1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  DragText := nil // Done
end;

end.
