• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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

Hello

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.
                              MemHandleUnlock(ChoicesHandle);
                              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.
                              MemHandleUnlock(RecHandle);
                              
                              // 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);
                  
                  }
                  

            FrmDrawForm(frmP);
            handled = true;
            break;
             
              case frmCloseEvent:      // The form was told to close.
                  // Free the memory blocks allocated for the list.      
                                         
                  if (ChoicesHandle)
                        {
                        MemHandleFree(ChoicesHandle);
                        ChoicesHandle = 0;
                        MemHandleFree(ChoicesPtrsHandle);
                        }
                  break;
                  
            case ctlSelectEvent:
           return ViewOffencesFormDoCommand(eventP->data.ctlSelect.controlID);       
       
        default:
            break;
        }
   
    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:
             FrmGotoForm(MainForm);
            break;
            
    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]));       
          MemHandleUnlock(RecordHandle);
          DmReleaseRecord(gDatabase, Index, true);
          //Index++;
          
          
          
            FrmAlert(SavedAlert);
          FrmGotoForm(ViewOffencesForm);
          
               handled = true;
              break;            

      }
       

    return handled;  
}
      
Please help me, im really stuck....
Thanking you
Tim
0
cantona12
Asked:
cantona12
1 Solution
 
seguretCommented:
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"...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now