Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top