Thanks for your replies Pinus and Don,
It's hard for me to create a self contained example that replicates the
problem. I can however get rid of the overhead in my previous example and
add comments to show exactly what's going on.
I've changed things a bit, but I still get the same problem of some of my
objects dying.
Classes used in this example:
TBStructure - A class that handles the dynamic creation of a Textbox, as
well as loading Text related to that textbox from a database. Also deals
with saving Text to a database.
AppMain - Deals with reading from a database that contains information on
form elements, which then renders the elements on pages.
Functions:
PopulatePage() - AppMain - This renders the page with the form elements
related to that page.
DePopulatePage() - AppMain - Removes all previously created objects on the
page and saves their state.
saveText() - TBStructure - Saves the current textbox's Text to a database.
What I'm trying to do:
When a TBStructure is created, I need to keep hold of that structure for
when the page is changed. When the page is changed
I call DePopulatePage then PopulatePage. When the page is DePopulated I
must save the input into all the textboxes, I must then access each
TBStructure and call saveText on each.
Code:
First I allocate a *TBStructure Pointer to hold the TBStructures:
AppMain: Global
----------------
int numFields = 0;
TBStructure *Fields = NULL;
----------------
In populatePage I search through the database and Get the number of
Textboxes for that page. I then allocate memory for the amount of
TBStructures I will need:
AppMain: PopulatePage()
------------------
UInt16 numFieldAlloc = 0;
for(i = 0; i < DmNumRecords(dbP); i++)
{
UInt16 type;
UInt16 page;
tbH = (MemHandle)DmQueryRecord(dbP, i);
dbRecP = (DBRecordPtr)MemHandleLock(tbH);
type = string2int(dbRecP->Type);
page = string2int(dbRecP->Page);
MemHandleUnlock(tbH);
if(page == CurrentPage)
{
if(type == textboxType)
{
numFieldAlloc++;
}
}
}
Fields = (TBStructure*)malloc(numFieldAlloc*sizeof(TBStructure));
-------------------------
I then search through the database again and on each Textbox Record found I
create a TBStructure and allocate it a place on the array:
AppMain: PopulatePage()
-------------------------
for(i = 0; i < DmNumRecords(dbP); i++)
{
UInt16 type;
UInt16 page;
tbH = (MemHandle)DmQueryRecord(dbP, i);
dbRecP = (DBRecordPtr)MemHandleLock(tbH);
type = string2int(dbRecP->Type);
page = string2int(dbRecP->Page);
MemHandleUnlock(tbH);
if(page == CurrentPage)
{
if(type == textboxType)
{
...../* non-relevant code */
(*(Fields+numFields)) =
TBStructure(string2int(tbP->X),string2int(tbP->Y),
string2int(tbP->Width),string2int(tbP->Height),
lastID++);
..../* non-relevant code */
}
..../* non-relevant code */
}
..../* non-relevant code */
}
----------------------
When I depopulate the page I must call the saveText function on each of the
TBStructures stored in the array:
AppMain: DePopulatePage()
---------------------
StrPrintF(name,"%s","LoadPDB");
locID=DmFindDatabase(0,name);
locID=DmFindDatabase(0,name);
dbP = DmOpenDatabase(0, locID, dmModeReadWrite);
for(j = 0; j < numFields; j++)
{
Fields[j].saveText(frmPtr, dbP);
}
DmCloseDatabase(dbP);
numFields = 0;
free(Fields);
----------------------
The Problem: Only the last textbox created on each page calls the saveText
function. I thought maybe I incremented numFields wrong... but it is
correct. I have not used it in any other place except those stated above.
I've tried replacing the code in setText to print characters on the window
stating the UID (Unique ID for each control from the database) and only the
UID of the last created TBStructure prints out.
I am utterly confused about this. I will appreciate any help at all about
this.
Thanks for your time, sorry about the long post.
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/