Search code examples
delphitextboxheightfiremonkey

Firemonkey TEdit height


I'm using Delphi Seattle and my application is for Windows Desktop.

I'm trying to change the font size of a TEdit. Consequently the height was also modified. At design time everything works well, but when I run my application TEdit ignores the height modification and the text is cut.

I've tried to find FixedHeight as suggested here, but I couldn't find this property.

Is it possible to change TEdit Heigth?


Solution

  • This can be solved by overriding the control’s AdjustFixedSize method. As explained by @chrisrolliston, Removing a FMX control’s size restrictions and exemplified here:

    unit Unit4;
    interface
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Edit, MyTEdit;
    
    type
      TForm4 = class(TForm)
        Edit1: TEdit;
        procedure FormCreate(Sender: TObject);
      end;
    
    var
      Form4: TForm4;
    
    implementation
    
    {$R *.fmx}
    
    procedure TForm4.FormCreate(Sender: TObject);
    begin
      Edit1.Height := 60;
    end;
    
    end.
    

    unit MyTEdit;
    interface
    uses
      FMX.Edit, FMX.Controls;
    
    type
      TEdit = class(FMX.Edit.TEdit)
      protected
        procedure AdjustFixedSize(const Ref: TControl); override;
      end;
    
    implementation
    uses
      FMX.Types;
    
    procedure TEdit.AdjustFixedSize(const Ref: TControl);
    begin
      SetAdjustType(TAdjustType.None);
    end;
    
    end.