BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why do some Paradox tables allow me to add a new field at ru

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Maximus
Guest





PostPosted: Sun Jun 15, 2008 9:10 am    Post subject: Why do some Paradox tables allow me to add a new field at ru Reply with quote



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;
Back to top
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group
.