0
votes

i have 2 tframes, and an add button. I am trying to add one tframe onto the other when the button is press. but for w.e reason my code can't seem to work. it's not adding the frame like it's suppose to. there is no errors or running, it compiles and runs, but when i press the button it does nothing. i got it to work when i added a tframe to a scrollbox, and all i did was change the location for the tframe to be added.

code for TFrame2

void __fastcall TFrame2::AddFrame()
{
    int temp = 0;
    TFrame1* NewFrame1 = new TFrame1(this);
    NewFrame1 ->Parent=this;

    TComponentEnumerator * ParentEnum = GetEnumerator();

    while(ParentEnum->MoveNext())
    {
        temp++;
    }

    NewFrame1 ->SetIndex(temp);
    NewFrame1 ->Name = "Frame" + IntToStr(temp);
    NewFrame1 ->Top = ( NewFrame1 ->Height ) * (temp);
}

this is the code i use for TFrame1 itself

void __fastcall TFrame1 ::SetIndex(int temp)
{
    this->temp= temp;
}

int __fastcall TFrame1 ::GetIndex()
{
    return this->temp;
}

a lil bg info: the reason i have to add tframe to another tframe, is so i can add a group of components onto another group of components, i didn't know any other way to do it. later on i add tframe2 onto the main form.

1
You need to be more specific. "my code cant seem to work" gives us absolutely nothing to go on. When things don't work, you need to be specific about how they don't work, including any specific error messages you get. Please remember we can't read your mind or your screen from here, so the only info we have is what you give us in your question. - Ken White
BTW, TFrame1* NewFrame1 = new TFrame1(TFrame2); is wrong. Change the parameter passed (the Owner) from TFrame2 to this. TFrame2 is a type, and you need to pass a pointer to a reference instead. - Ken White
i added more details to y the code doesn't work. it just simply run without error, but no tframe is added. i have tried 'this' instead of TFrame2, same thing, the code runs, but o tframe is added when i press the button - livelaughlove

1 Answers

0
votes

Given the code you have shown, the only thing that could be going wrong is if you are setting the child frame's Top property to a value that exceeds the Height property of its parent frame so that you would not see the child frame appear onscreen even though it does exist in memory.