----- Original Message ----- 
From: "Andre Augusto" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[email protected]>
Sent: Friday, April 29, 2005 11:08
Subject: Translation code problems...


> Hello everybody!
> I have a little problem in my hands! A friend of mine ask me to
> translate a Palm programm writen in Pascal, to C!
> But i don't remember very well some things associated with that language!
>
> I have a struct like this
> type
>   TEmptyRecord = record
>     Rating : UInt16;
>     Name   : PChar;
>     Notes  : PChar;
>   end;
>
> .. that I put in C like this
> typedef struct DBRecord
> {
>     UInt16 Rating;
>     char Name;
>     char Notes;
> } DBRecord;
> static DBRecord        record;
> typedef DBRecord* DBRecordPtr;

No need for the "static DBRecords record", eg. the pascal code doesn't
declare a variable

>
> Now i have this function in Pascal and put it to C. Can anyone tell me
> if it's correct? I don't know very well what is the
>
> EmptyRecord : TEmptyRecord means......
> Thanks to everybody!
> Andr� augusto
>
>
> procedure AddRecord;
>   var
>     RecordIndex : UInt16;
>     EmptyRecord : TEmptyRecord;
>     RecordPtr   : Pointer;
> begin
>   // Normally would want to sort the database somehow, and allow deleted
and
>   // archived records, in which case this technique is dangerous
>   RecordIndex   := dmMaxRecordIndex;
>   CurrRecHandle := DmNewRecord(BeerDb,RecordIndex,SizeOf(EmptyRecord));
>
>   if CurrRecHandle = nil then begin
>     FrmCustomAlert(ErrorAlert,'Can''t create a new record','','');
>     Exit;
>   end;
>
>   // Initialize the new record
>   RecordPtr := MemHandleLock(CurrRecHandle);
>   // Set contents of empty record to all zeroes
>   MemSet(@EmptyRecord,SizeOf(EmptyRecord),0);
>   // Write empty record to start of record - cannot have zero length
records
>   DmWrite(RecordPtr,0,@EmptyRecord,SizeOf(EmptyRecord));
>   MemHandleUnlock(CurrRecHandle);
>
>   // Using temporary variable in case of failure to create a record
>   CurrRecNumber := RecordIndex;
>
>   // Load the editing form
>   FrmGotoForm(EditForm);
> end;
>
>
>
> void AddRecord()
> {
>   UInt16 RecordIndex;
>   DBRecordPtr TEmptyRecord; //????????????
>   DBRecordPtr  RecordPtr;

    DbRecord EmptyRecord  ;
    DBRecordPtr RecordPtr ;

    General rule:
    In pascal you write:   var1 (, var2, var3, ...) : interger
    In C : int var1, var2, var3 ...



>
>   // Normally would want to sort the database somehow, and allow deleted
and
>   // archived records, in which case this technique is dangerous
>   RecordIndex = dmMaxRecordIndex;
>
>   CurrRecHandle = DmNewRecord(BeerDb, &RecordIndex, sizeof(TEmptyRecord));

   CurrRecHandle = DmNewRecord(BeerDb, &RecordIndex, sizeof(DBRecord));

>
>   if (CurrRecHandle == NULL)
>   {
>     FrmCustomAlert(ErrorAlert, "Can't create a new record", "", "");
>     return;
>   }
>
>   // Initialize the new record
>   RecordPtr = (DBRecordPtr) MemHandleLock(CurrRecHandle);
>
>   // Set contents of empty record to all zeroes
>   MemSet(&TEmptyRecord, sizeof(DBRecordPtr), 0);

   MemSet(&EmptyRecord, sizeof(DBRecord), 0);

>
>   // Write empty record to start of record - cannot have zero length
records
>   DmWrite(RecordPtr, 0, &TEmptyRecord, sizeof(TEmptyRecord));

   DmWrite(RecordPtr, 0, &EmptyRecord, sizeof(DBRecord));

>
>   MemHandleUnlock(CurrRecHandle);
>
>   // Using temporary variable in case of failure to create a record
>   CurrRecNumber = RecordIndex;
>
>   // Load the editing form
>   //FrmGotoForm(EditForm);
> }

Regards
    Miro Pomsar

>
>
>
> -- 
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to