🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi
1 messages
1 total messages Started by Maximus Sun, 15 Jun 2008 09:10
Why do some Paradox tables allow me to add a new field at runtime and others give a Number is out of Range exception?
#219
Author: Maximus
Date: Sun, 15 Jun 2008 09:10
74 lines
3836 bytes
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:

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;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads