Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you add a new field to Paradox table at runtime successfully?

Status
Not open for further replies.

BebopSong

Programmer
Apr 3, 2008
10
GB
Hi all,

I am trying to create an update program that will scan two databases,
the clients database and the new updated database, for any changes,
i.e. new fields, longer field lengths or new tables, etc.

I can add new tables and amend field lengths without a hitch but when
I try to add a new field to a table I get an array of results. Some
tables will allow a field to be added whereas others will bring up
errors such as "Number is out of range" or "Invalid field
descriptor".

Has anyone seen these errors before and could you please explain why I
might be getting these? Thank you in advance for any help.

P.S. The code i am using to add a new field is below:

Code:
procedure TLodgeUpdateForm.AddField(Table : TTable; FldName : String;
                                     FldType,
FldSubType,FldSize:Integer);
type
  FLDDescs = array [1..100] of FLDDesc;   // these are kludges for
ease of addressing
  PFLDDescs = ^FLDDescs;
  CROpTypes = array [1..100] of CROpType;
  PCROpTypes = ^CROpTypes;
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;
  pFields: pFLDDescs;
  pOp: pCROpTypes;
  i:Integer;
begin
 // Make sure table is opened exclusively
 If (Table.Active and Not Table.Exclusive) Then Table.Close;
 If (Not Table.Exclusive) Then Table.Exclusive := True;
 If (Not Table.Active) Then Table.Open;
 try
   Check(DbiGetCursorProps(Table.Handle, Props));
   pFields := AllocMem((props.iFields+1) * sizeof(FLDDesc));
   pOp := AllocMem((props.iFields+1) * sizeof(CROpType));
   Check(DbiGetFieldDescs(table.Handle,@PFields[1]));
   for i := 1 to props.iFields do   // retain existing fields
     pop^[i] := crNOOP;
   i := props.iFields + 1;
   pOp^[i] := crADD;
   with PFields^[i] do
      begin
         StrCopy(szName,PChar(FldName));
         iFldType := FldType;
         ISubType := FldSubType;
         IUnits1 := FldSize;
      end;
      FillChar(tabledesc,sizeof(CRTblDesc),#0);
      with tabledesc do
         begin
             StrPCopy(szTblName,Table.TableName);
             StrCopy(szTblType,szParadox);
             bPack := True;
             iFldCount := props.iFields+1;
             pecrFldOp := @pop^[1];
             pfldDesc := @pfields^[1];
         end;
      Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE,
hDBIObj(hDb)));
      Table.Close;// table must be closed as restructure requires
exclusive access
      Check(DbiDoRestructure(hdb,1,@tabledesc,nil,nil,nil,False));
   finally
     FreeMem(PFields);
     FreeMem(pOp);
   end;
end;
 
If it was actual data within the table, I'd ask if append would be better than open for new writing new descriptions at the end. Not sure if the same actually applies to the table structure though.

The Invalid field descriptor suggests to me that the field type being written doesn't match criteria set.
ie. Trying to write a memo field but expecting a 5 digit numeric field.


My Feeblegirl.com Forum boards for mmorpgs, sport, fun, politics...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top