0

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.

livelaughlove
  • 376
  • 3
  • 9
  • 21
  • 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 Feb 16 '12 at 15:25
  • 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 Feb 16 '12 at 15:26
  • 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 Feb 16 '12 at 17:54

1 Answers1

0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • i double checked everything and this wasn't the case, yet it still won't work. I'm not quite sure why. I will just try to do this a different way. thanks though for your contribution. – livelaughlove Feb 21 '12 at 17:11
  • i finally figured out what was wrong after leaving this aside for a while. it wasn't anything to do with my code..it was simply C++ Builder's bug. every time i go into design view to make adjustments, i have to go back to my code and comment out the winproc stuff, save it, then uncomment the winproc stuff, and save it again, and then it would work. i'm not quite sure y that is but it solves the problem. – livelaughlove Mar 02 '12 at 19:00
  • What bug are you referring to? I've never had to do what you described. – Remy Lebeau Mar 02 '12 at 23:42
  • it's really weird. remember how you taught me to add/delete Tframes at run time http://stackoverflow.com/questions/9163664/deleting-tframe-from-form-at-run-time. well it works fine, except if i decide to make some changes in design view, for whatever reason, when i try to run it, it will give me an error that says "Error in module __cpp_file__ Incorrect method declaration in class __tframe__." I would have to comment out __property TNotifyEvent OnClose = {read=FOnClose, write=FOnClose}; and TNotifyEvent FOnClose; in .h , save it, uncomment them, save it again, then everything would run again – livelaughlove Mar 05 '12 at 19:30