CompuServe Messages

Dynamic gadget creation

    28-Apr-94 19:26:40
Sb: Dynamic gadget creation
Fm: jack york 71562,3372
To: all
I need to be able to create a variable number of gadgets on the fly. I came up with the following function to accomplish this (the actual funtion would contain a loop). However, after running it and clicking on the gadget a few times, if I try to recompile, the computer traps with a corrupted memory error. Sometimes it fails after the first run, sometimes after a few runs. Can anyone tell me where the mistake is or if I am going about this all wrong? Thanks, Jack. in calling fcn… if ((soft_gad = (struct Gadget *) MakeSoftGad()) != NULL) { hard_gad.NextGadget = soft_gad; /*link to gadget present from compile time*/ RefreshGadgets(&hard_gad, my_window, 0L); } APTR MakeSoftGad(void) /*attempt to create one gadget*/ { struct Gadget *CurGadPtr; if (AllocRemember(&RememGadget, sizeof(struct Gadget), MEMF_CHIP | MEMF_CLEAR)) { CurGadPtr = (struct Gadget *) RememGadget->Memory; CurGadPtr->NextGadget = NULL; CurGadPtr->LeftEdge = 40; CurGadPtr->TopEdge = 60; CurGadPtr->Width = 34; CurGadPtr->Height = 9; CurGadPtr->Flags = GADGHCOMP; CurGadPtr->Activation = GADGIMMEDIATE | TOGGLESELECT; CurGadPtr->GadgetType = BOOLGADGET; CurGadPtr->GadgetRender = NULL; CurGadPtr->SelectRender = NULL; CurGadPtr->GadgetText = NULL; CurGadPtr->MutualExclude = NULL; CurGadPtr->SpecialInfo = NULL; CurGadPtr->GadgetID = 0; CurGadPtr->UserData = NULL; return(CurGadPtr); } return(NULL); }