Getting a  field from the Database and displaying in a list:

Posted on 2003-03-12
Medium Priority
Last Modified: 2013-12-27

Im having this problem. In the first form of my application i enter a Car Registration number in a field, in all other other forms i enter car details associated with that Car Registration number, and when i enter all the Car Details i save it to the database on the PalmPilot. When it saves it, it puts the Car Registration number in a list on a viewDatabase form, so when  i want to view the database, i see the the first registration number in the list, i click it and it shows me all the details to do with that registration number. The problem is that when i start again, ie put in a registration number, and all the associated details, and save etc, it overwrites the registration number that i previously entered, instead of putting it below the Registration Number, and i entered previously.

My email address is 9939318@student.ul.ie
I think that its a problem with my Index, when i write to the database.
Here is some of code below

This first of all puts the Location on top of the list, ina  nother form

Boolean ViewOffencesFormHandleEvent(EventType * eventP)
    Boolean handled = false;
    FormType * frmP;
    Char *choices;
      ListPtr      lst;
      UInt16 itemIndex, textLen, choicesOffset = 0, i;
      UInt16 NumRecords = 1;
      Err      error;
      FYPDB *RecordPointer2;
      //UInt16 index = 0;

    switch (eventP->eType)

      LstSetSelection(GetObjectPtr(ViewOffencesRegNumbersList), -1);
      case frmOpenEvent:
        // Get a pointer to the main form.          
          frmP = FrmGetActiveForm();

            // Get the number of records currently in the application's database.
            NumRecords = DmNumRecords(gDatabase);
            if (NumRecords)
                  // Prepare to setup the contents of the list for the main form.
                  // Get a pointer to the list object.
                  lst = GetObjectPtr(ViewOffencesRegNumbersList);
                  //itemIndex = FrmGetObjectIndex(frmP, ViewOffencesRegNumbersList);
                  //lst = FrmGetObjectPtr(frmP, itemIndex);
                  // Allocate an initial block for the list choices.
                  ChoicesHandle = MemHandleNew(sizeof(char));
                  // Lock down the block and set it's initial value to an empty string.
                  choices = MemHandleLock(ChoicesHandle);
                  *choices = 0;
                  // Build up the choices.  
                  // A sequence of strings packed one after another, one for each record.
                  for (itemIndex = 0; itemIndex < NumRecords; itemIndex++)
                              // Retrieve the record from the database and lock it down.
                              RecHandle = DmGetRecord(gDatabase, itemIndex);
                              RecordPointer2 = MemHandleLock(RecHandle);
                              textLen = StrLen(RecordPointer2->Location);

                              // Grow the choices buffer to accomodate the new string. We must unlock
                              // the chunk so that the Memory Manager can move the chunk if neccessary to
                              // grow it.
                              error = MemHandleResize(ChoicesHandle, textLen + choicesOffset + sizeof('\0'));
                              choices = MemHandleLock(ChoicesHandle);
                              // Check for fatal error.
                              ErrFatalDisplayIf(error, "Could not grow choices for list.");
                              // Copy the text from the record to the choices buffer.
                              for (i = 0; i < textLen; i++)
                                    choices[choicesOffset + i] = RecordPointer2->Location[i];
                              // Update the end of choices offset and set a zero terminator
                              // on the string in the choices buffer.
                              choicesOffset += textLen;
                              choices[choicesOffset++] = 0;
                              // Unlock the handle to the record.
                              // Release the record, not dirty.
                              DmReleaseRecord(gDatabase, itemIndex, false);
                  // Create an array of pointers from the choices strings.
                  ChoicesPtrsHandle = SysFormPointerArrayToStrings(choices, NumRecords);
                  // Set the list choices from the array of pointers.
                  LstSetListChoices(lst, MemHandleLock(ChoicesPtrsHandle), NumRecords);

            handled = true;
              case frmCloseEvent:      // The form was told to close.
                  // Free the memory blocks allocated for the list.      
                  if (ChoicesHandle)
                        ChoicesHandle = 0;
            case ctlSelectEvent:
           return ViewOffencesFormDoCommand(eventP->data.ctlSelect.controlID);       
    return handled;

This is the form where i write the details to the database

Boolean FinalFormDoCommand(UInt16 command)
   Boolean handled = false;
         FYPDB CarDetails[2];
         MemHandle RecordHandle;
    char *RecordPointer1;
    FormType * frmP;    
   switch (command)
    case FinalBackButton:
    case FinalSaveButton:
          frmP = FrmGetActiveForm();

            CarDetails[Index].RegNum = outputString;
          CarDetails[Index].Location = outputString2;
          CarDetails[Index].Colour = outputString3;
          CarDetails[Index].CarType = outputString4;
               CarDetails[Index].Offence = outputString5;
          RecordHandle = DmNewRecord(gDatabase, &Index, 64);
          RecordPointer1 = MemHandleLock(RecordHandle);
          DmWrite(RecordPointer1, 0, &CarDetails[Index], sizeof(CarDetails[Index]));       
          DmReleaseRecord(gDatabase, Index, true);
               handled = true;


    return handled;  
Please help me, im really stuck....
Thanking you
Question by:cantona12
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

seguret earned 300 total points
ID: 8128223
You should precise the index of the record. You seems to always write at index 0.

By the way, don't forget that c is case-sensitive, so "Index" is not the same than "index"...

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator (https://www.appcelerator.com/). This article presumes a wor…
Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question