Error when dynamically creating more than one Frame at runtime (C++, FMX, IDE: C++ Builder)

  

I would like to dynamically create a series of Frame components, then save the pointers into a vector.

I am able to dynamically create TEdit components with no problem, but if I replace TEdit with the name of the frame component (that contains an edit box) the program will error. The first frame will be created, but errors when creating the second one, stating “External exception EEFFACE”

Here is the relevant code. Note that if I replace TFrame2 with TEdit, it works.

class TForm1 : public TForm
{

public: // User declarations
std::vector<TFrame2*> fields;

};

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TFrame2* temp = new TFrame2 (Layout1);
temp->Parent = Layout1;
temp->Align = TAlignLayout::Top;
fields.push_back(temp);
count++;
}

This is what it looks like after one click.

Error message after 2 clicks.

This is how I want it to look after two clicks.

This is what it looks like when I replace TFrame2 with TEdit, after 3 clicks.

EDIT

If I try to hard-code the creation of two Frames, I get the same error on the first click.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TFrame2* temp = new TFrame2 (Layout1);
temp->Parent = Layout1;
temp->Align = TAlignLayout::Top;
fields.push_back(temp);
count++;

TFrame2* temp1 = new TFrame2 (Layout1);
temp1->Parent = Layout1;
temp1->Align = TAlignLayout::Top;
fields.push_back(temp1);
count++;

}

EDIT 2

In this post

Can FireMonkey frames be created dynamically?

I see a comment that states

I should note here that it seems the frame objects need to be assigned a unique Name property manually right after creation, at least when using C++, or the next frame object created of the same type will try to take the same name as the first one.

Comments are closed.