use of undeclared identifier 'akBottom'

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

use of undeclared identifier 'akBottom'

Postby chaplin.u » Wed Jan 31, 2018 2:23 am

I use FMX to create Android application. I create component in runtime and have problem with anchors.
headers #include <System.UITypes.hpp> and #include <FMX.Controls.hpp> placed but this code :

CheckBox->Anchors <<= akBottom; receive error "use of undeclared identifier 'akBottom'"

this version : CheckBox->Anchors = TAnchors() << akTop << akRight; not work too :(

What to do ?
chaplin.u
Active Poster
Active Poster
 
Posts: 10
Joined: Wed Mar 29, 2017 1:43 am

Re: use of undeclared identifier 'akBottom'

Postby HsiaLin » Wed Jan 31, 2018 2:49 pm

Code: Select all
 CheckBox->Anchors = CheckBox->Anchors << akTop << akRight;
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 297
Joined: Sun Jul 08, 2007 6:29 pm

Re: use of undeclared identifier 'akBottom'

Postby rlebeau » Wed Jan 31, 2018 7:11 pm

chaplin.u wrote:I use FMX to create Android application.


FMX is compiled with Scoped Enums enabled, so you must prefix an enum member with the enum's type name, eg:

Code: Select all
CheckBox->Anchors <<= TAnchorKind::akBottom;


Or:

Code: Select all
CheckBox->Anchors = TAnchors() << TAnchorKind::akTop << TAnchorKind::akRight;
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1508
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: use of undeclared identifier 'akBottom'

Postby rlebeau » Wed Jan 31, 2018 7:14 pm

HsiaLin wrote:
Code: Select all
 CheckBox->Anchors = CheckBox->Anchors << akTop << akRight;


Although what you said is technically true, it doesn't solve the issue at hand, and as chaplin.u already said, using that syntax (whether you use CheckBox->Anchors or TAnchors() doesn't matter) is not working, either. See my other reply for why that is.

Also, note that the CLang-based compilers, like the Android compiler, support compound operators on properties, so using the <<= operator on the Anchors property is actually valid syntax.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1508
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: use of undeclared identifier 'akBottom'

Postby chaplin.u » Thu Feb 01, 2018 12:07 am

Thanks !!!
Now it's work ! :D
But it's not work as expected.
1. If not to use anchors it place component to Left Top.
2. Label->Anchors = TAnchors() << TAnchorKind::akBottom; make Right Top
3. Label->Anchors <<= TAnchorKind::akBottom; make Left Center
but can't to get Bottom of parent.
chaplin.u
Active Poster
Active Poster
 
Posts: 10
Joined: Wed Mar 29, 2017 1:43 am

Re: use of undeclared identifier 'akBottom'

Postby rlebeau » Thu Feb 01, 2018 12:45 pm

chaplin.u wrote:1. If not to use anchors it place component to Left Top.


As it should be. The default Anchors is set to [akLeft,akTop].

chaplin.u wrote:2. Label->Anchors = TAnchors() << TAnchorKind::akBottom; make Right Top


You are wiping out all Anchors and then enabling only the Bottom anchor. As such, the Left, Top, and Right will not be anchored.

chaplin.u wrote:3. Label->Anchors <<= TAnchorKind::akBottom; make Left Center


Now you are preserving all existing Anchors and then enabling the Bottom anchor as well. So, by default, the Left, Top, and Bottom will be anchored, but not the Right.

chaplin.u wrote:but can't to get Bottom of parent.


Do you understand what Anchors actually are? They control how a child control's edges move around in relation to its Parent when the Parent is resized. When a controls' edge is anchored, it stays in place relative to the corresponding edge of its Parent. When an edge is not anchored, it is free to move around based on the control's new dimension relative to the opposite edge.

If you want a Label to be sized and positioned along the bottom edge of the Parent, you probably want to use the Align property instead of the Anchors property.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1508
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: use of undeclared identifier 'akBottom'

Postby chaplin.u » Thu Feb 01, 2018 2:47 pm

I read http://docwiki.embarcadero.com/RADStudio/XE8/en/Arranging_FireMonkey_Controls :
Anchors are needed when a control must maintain its position at a certain distance from the edges of its parent
so if I use anchor to Bottom child must be close to Bottom edge of parent !?
BTW. I use this settings to new created in runtime child and parent not change sizes.
As I understand Aligning can resize control and I don't want it.
I have ListBox items as parent and some controls places on it (Labels, Checkboxes, ComboBoxes).
As you know sizes of smartphone displays is different so I want to place controls with different gaps.
chaplin.u
Active Poster
Active Poster
 
Posts: 10
Joined: Wed Mar 29, 2017 1:43 am

Re: use of undeclared identifier 'akBottom'

Postby chaplin.u » Thu Feb 01, 2018 4:01 pm

This example what I do
Untitled.png
Untitled.png (8.34 KiB) Viewed 6305 times

Green it's what I need and red is what I received.
source
Code: Select all
   TListBoxItem *Item;
   TLabel *Label;
   TCheckBox *CheckBox;

   NativeInt i = 2;
   NativeInt j = 1;

    // List Item
   Item = new TListBoxItem(this);
   Item->Parent = ListBox1;
   Item->StyleLookup = "listboxitemnodetail";
    Item->Height = 100;
   Item->Visible = true;
   Item->Text = String(i);


   // Child
   for (j=5; j>0; j--)
   {
   CheckBox = new TCheckBox(this);
   CheckBox->Parent = Item;
   CheckBox->Height = 40;
   CheckBox->Width  = 40;
   CheckBox->Text = String(j);

   CheckBox->Align = TAlignLayout::Left;
   CheckBox->Anchors  = TAnchors() << TAnchorKind::akBottom;
   CheckBox->Margins->Bottom  = 5;
   CheckBox->Margins->Left = 5;
   }

   Label = new TLabel(this);
   Label->Parent = Item;
   Label->Text = "Select 2 :";
   Label->Align = TAlignLayout::Bottom;
   Label->Margins->Bottom  = 10;
   Label->Margins->Left = 10;


chaplin.u
Active Poster
Active Poster
 
Posts: 10
Joined: Wed Mar 29, 2017 1:43 am

Re: use of undeclared identifier 'akBottom'

Postby rlebeau » Thu Feb 01, 2018 4:31 pm

chaplin.u wrote:I read http://docwiki.embarcadero.com/RADStudio/XE8/en/Arranging_FireMonkey_Controls :
Anchors are needed when a control must maintain its position at a certain distance from the edges of its parent
so if I use anchor to Bottom child must be close to Bottom edge of parent !?


No. If the child is anchored on the bottom, then whenever the Parent is resized, the distance between the child's bottom edge and the Parent's bottom edge will be maintained at a fixed distance, regardless of where the child is positioned within the Parent. That does not mean the child has to be positioned near the Parent's bottom edge at all.

Think of an Anchor like gluing one end of a stick onto a child's edge, and gluing the other end of the stick onto the corresponding edge of the child's Parent. Whenever the Parent resizes, each affected edge on the Parent moves around all of the sticks that are glued to it, thus moving around the attached child edges. But the sticks themselves don't change their sizes (the distance between a child's edge and its Parent's edge).
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1508
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: use of undeclared identifier 'akBottom'

Postby chaplin.u » Fri Feb 02, 2018 3:18 am

I`m confused :cry:
My form is not moved and not resized. I just want to put controls in the right place inside parent.
I tried align and anchors but still not success. What's wrong ?
chaplin.u
Active Poster
Active Poster
 
Posts: 10
Joined: Wed Mar 29, 2017 1:43 am

Re: use of undeclared identifier 'akBottom'

Postby rlebeau » Mon Feb 05, 2018 2:04 pm

chaplin.u wrote:I`m confused :cry:
My form is not moved and not resized.


That you know of. The OS, or FMX, could be doing it behind the scenes, especially while the Form is being created and streamed in from its DFM at runtime.

chaplin.u wrote:I just want to put controls in the right place inside parent.


Then why are you messing around with the Anchors at all? Just leave them alone. The default of [akLeft,akTop] is enough to let the controls be positioned wherever you place them at design-time.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1508
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: use of undeclared identifier 'akBottom'

Postby rlebeau » Mon Feb 05, 2018 2:15 pm

chaplin.u wrote:This example what I do
Untitled.png

Green it's what I need and red is what I received.


Why are you creating the child controls in reverse order? You are creating the CheckBoxes from 5 to 1, placing a new CheckBox on the left of the previous CheckBox, and then you are creating the Label. Why not create the Label first and then create the CheckBoxes 1-5? Then you don't need to mess with the Align or Anchors at all.

Code: Select all
TListBoxItem *Item = new TListBoxItem(this);
Item->Parent = ListBox1;
Item->StyleLookup = "listboxitemnodetail";
Item->Height = 100;
Item->Visible = true;
Item->Text = String(i);

TLabel *Label = new TLabel(this);
Label->Parent = Item;
Label->Text = "Select 2 :";
Label->Left = 10;
Label->Top = Item->Height - 10 - Label->Height;

int left = Label->Left + Label->Width + 5;
int top = Item->Height - 45;
for (int j = 1; j <= 5; ++j)
{
    TCheckBox *CheckBox = new TCheckBox(this);
    CheckBox->Parent = Item;
    CheckBox->Height = 40;
    CheckBox->Width  = 40;
    CheckBox->Text = String(j);
    CheckBox->Left = left;
    CheckBox->Top = top;
    left += (CheckBox->Width + 5);
}
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1508
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: use of undeclared identifier 'akBottom'

Postby chaplin.u » Tue Feb 06, 2018 1:42 am

because it move next created control closer that previous. and as result order is revert.
I see that this way is not success so I'll place with position :(
chaplin.u
Active Poster
Active Poster
 
Posts: 10
Joined: Wed Mar 29, 2017 1:43 am


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 14 guests