Daniel Grillo
Daniel Grillo

Reputation: 2428

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?

Upvotes: 5

Views: 3332

Answers (3)

LU RD
LU RD

Reputation: 34939

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.

Upvotes: 5

alitrun
alitrun

Reputation: 1218

If your're using styles in StyleBook:

  1. First check style name in EditBox - look at StyleLookup of TEdit in Object inspector. If it's empty, that means default editstyle for Editbox. You should search this name in styles.
  2. Open current style, select you platform, find editstyle in a list of styles.
  3. Change FixedHeight to 0. Also you can set Align = None to reset align height.

Upvotes: 2

Roy Woll
Roy Woll

Reputation: 322

Another way to handle this if you don't want to have to subclass and create your own Edit is to use a cheating cast to perform this. This gives you access to protected methods of Edit (SetAdjustType). The following example assumes you have a Edit named wwedit3.

type
  THackStyledControl = class(TStyledControl);

procedure TValidationDemoForm.FormCreate(Sender: TObject);
begin
  wwedit3.ApplyStyleLookup; // Necessary or AdjustType gets overwritten
  THackStyledControl(wwedit3)  // Removes fixed height
        .SetAdjustType(TAdjustType.None);
  wwedit3.height:= 60; // Reset the height to desired value
end;

This will work, but if you are hard coding your sizes then you need to explicitly reset your height property as the code does above. If instead you are using the align property to position your edit controls, then you don't need the additional line that sets wwedit3.height to 60

Upvotes: 1

Related Questions