Jump to content
ptlycldy

TTextAlign problems in TEdit in FMX

Recommended Posts

I'm new to FMX (VCL is easier)  but I've encountered a problem and all the Embarcadero wiki's don't seem to help.

 

I have a FMX TEdit box  with text.   I can position  the text to "Center"  in the box at design time by going to  TextSettings->HorzAlign->Center    in the object inspector and all goes well.  It compiles.   But I would like to change the alignment at runtime in the code when a button is clicked.  

 

The code I use is :    Edit1->TextSettings->HorzAlign = Leading ;          //Leading means left justified

 

and the error message on compiling is:  use of undeclared identifier 'Leading'       I have included the file FMX.Types.hpp  which should (does: I checked) tell the compiler about Leading.

 

Where  Leading    is  given as     "enum class DECLSPEC_DENUM TTextAlign : unsigned int { Center, Leading, Trailing };  "   in the embarcadero wiki at FMX.Types.TTextAlign - RAD Studio API Documentation (embarcadero.com)

(Sorry folks--  I'm a C++ guy  but this should be the same problem for you Delphi folks as well)   

 

So I added the code:   

 unsigned int Center, Leading, Trailing;
   Center = 0;
   Leading = 1;
   Trailing = 2;

 

And get error:   cannot initialize a parameter of type 'FMX::Types::TTexAlign' with an lvalue of type 'unsigned int'

 

What am I doing wrong?  But more important,  how can I get the Edit box to change alignment during runtime?

 

Thanks for your ideas.

 

Ptlycldy

 

 

 

 

 

 

Edited by ptlycldy

Share this post


Link to post

Hi,

 

You need to give the type of the enumeration, use

Edit1->TextSettings->HorzAlign =TTextAlign.Leading
Edit1.TextSettings.HorzAlign :=TTextAlign.Leading

 

28 minutes ago, ptlycldy said:

I'm new to FMX (VCL is easier)

It's only some ways to change. I use Delphi from D3 version, my new applications are all FMX, it took me 1-2 years to take the plunge, but now I much prefer FMX

  • Like 1

Share this post


Link to post
  1. some "enumerates" needs "spacenames" for use, or you can have a "conflict" between same "enumerate name" in many others units!
    1. then, try always use "enumarateNameSpaces.enumerateValue", like: TMyEnumX.meTwo
  2. other way to use enumerates, if no "out of range" from enumerate in usage, is:

 

implementation   /// DELPHI code

{$R *.dfm}

type
  TMyEnumX = (meOne, meTwo); // <-------

 

procedure ShowMePlease;
var
  MyEnumX : TMyEnumX;
  MyVarInt: integer;
begin
  MyVarInt := 4; // <------- it will 5º element, if exists on enumerate type above!
  //
  MyEnumX := TMyEnumX( MyVarInt ); // <------- OUT OF RANGE here, but not error!
  //
  ShowMessage( Ord(MyEnumX).ToString ); // no errors here!!
end;

end.

 

 

image.thumb.png.1b13264579875b5595969f1210076e20.png

Edited by programmerdelphi2k

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×