?
Solved

crMODIFY & DBase Files. How to use?????:(

Posted on 1998-07-21
7
Medium Priority
?
317 Views
Last Modified: 2013-11-24
My question is as follows,

How on earth do you use crMODIFY to alter the fields in a dataset other than the first one. I can use it successfully to edit the first fields Type,Width and precision but am unable to modify any other field as I keep getting
"invalid restructure operation" . Does anyone have some code to show the correct way to step through a list of field descriptors as I am at my wits end trying to solve this. Surely someone has done this before?? I can also use the crAdd and crDrop successfully but the crMODIFY has got me stumped. I have already had a look at some source that just shows how to Add a new field but gee I need something more than that as I has adjusted the code to suit a modify operation and as I said it does alter/modify the first field descs in the DBase table but when it tries to do the DbiDoRestructure on the second field it crashes out every time. Anyone ??

Westy (PS Good points for this)

0
Comment
Question by:westy100697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 1000 total points
ID: 1358282
Hi westy,

have you already looked at the great examples at Inprise concerning DBE?

Guess this is exactly what you need, isn't it?

Here is an example :

Example 3: Alter a field in a Paradox or dBASE table.

                         This example will alter an existing field in a Paradox or dBASE table.
                         NOTE: You must fill in all options in the ChangeRec with 0 or '' if the option is not used in the restructure.
                         FillChar can be used to do this: Fillchar(MyChangeRec, sizeof(MyChangeRec), 0);
                         This example uses the following input:
                         ChangeField(Table1, Table1.FieldByName('FOO'), MyChangeRec)
                         ChangeRec is defind as follows:

                         ChangeRec = packed record
                             szName: DBINAME;
                             iType: word;
                             iSubType: word;
                             iLength: word;
                             iPrecision: byte;
                           end;

                         The function is defined as follows:

                         procedure ChangeField(Table: TTable; Field: TField; Rec: ChangeRec);
                         var
                           Props: CURProps;
                           hDb: hDBIDb;
                           TableDesc: CRTblDesc;
                           pFields: pFLDDesc;
                           pOp: pCROpType;
                           B: byte;

                         begin
                           // Initialize the pointers...
                           pFields := nil; pOp := nil;
                           // Make sure the table is open exclusively so we can get the db handle...
                           if Table.Active = False then
                             raise EDatabaseError.Create('Table must be opened to restructure');
                           if Table.Exclusive = False then
                             raise EDatabaseError.Create('Table must be opened exclusively to restructure');

                           Check(DbiSetProp(hDBIObj(Table.Handle), curxltMODE, integer(xltNONE)));
                           // Get the table properties to determine table type...
                           Check(DbiGetCursorProps(Table.Handle, Props));
                           // Make sure the table is either Paradox or dBASE...
                           if (Props.szTableType <> szPARADOX) and (Props.szTableType <> szDBASE) then
                             raise EDatabaseError.Create('Field altering can only occur on Paradox' +
                                         ' or dBASE tables');
                           // Allocate memory for the field descriptor...
                           pFields := AllocMem(Table.FieldCount * sizeof(FLDDesc));
                           // Allocate memory for the operation descriptor...
                           pOp := AllocMem(Table.FieldCount * sizeof(CROpType));
                           try
                             // Set the pointer to the index in the operation descriptor to put
                             // crMODIFY (This means a modification to the record is going to happen)...
                             Inc(pOp, Field.Index);
                             pOp^ := crMODIFY;
                             Dec(pOp, Field.Index);
                             // Fill the field descriptor with the existing field information...
                             Check(DbiGetFieldDescs(Table.Handle, pFields));
                             // Set the pointer to the index in the field descriptor to make the
                             // midifications to the field
                             Inc(pFields, Field.Index);

                             // If the szName portion of the ChangeRec has something in it, change it...
                             if Length(Rec.szName) > 0 then
                               pFields^.szName := Rec.szName;
                             // If the iType portion of the ChangeRec has something in it, change it...
                             if Rec.iType > 0 then
                               pFields^.iFldType := Rec.iType;
                             // If the iSubType portion of the ChangeRec has something in it, change it...
                             if Rec.iSubType > 0 then
                               pFields^.iSubType := Rec.iSubType;
                             // If the iLength portion of the ChangeRec has something in it, change it...
                             if Rec.iLength > 0 then
                               pFields^.iUnits1 := Rec.iLength;
                             // If the iPrecision portion of the ChangeRec has something in it, change it...
                             if Rec.iPrecision > 0 then
                               pFields^.iUnits2 := Rec.iPrecision;
                             Dec(pFields, Field.Index);

                             for B := 1 to Table.FieldCount do begin
                               pFields^.iFldNum := B;
                               Inc(pFields, 1);
                             end;
                             Dec(pFields, Table.FieldCount);
                             
                             // Blank out the structure...
                             FillChar(TableDesc, sizeof(TableDesc), 0);
                             //  Get the database handle from the table's cursor handle...
                             Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
                             // Put the table name in the table descriptor...
                             StrPCopy(TableDesc.szTblName, Table.TableName);
                             // Put the table type in the table descriptor...
                             StrPCopy(TableDesc.szTblType, Props.szTableType);
                             // The following three lines are necessary when doing any field restructure
                             // operations on a table...

                             // Set the field count for the table
                             TableDesc.iFldCount := Table.FieldCount;
                             // Link the operation descriptor to the table descriptor...
                             TableDesc.pecrFldOp := pOp;
                             // Link the field descriptor to the table descriptor...
                             TableDesc.pFldDesc := pFields;
                             // Close the table so the restructure can complete...
                             Table.Close;
                             // Call DbiDoRestructure...
                             Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
                           finally
                             if pFields <> nil then
                               FreeMem(pFields);
                             if pOp <> nil then
                               FreeMem(pOp);
                           end;
                         end;

Zif.
0
 

Author Comment

by:westy100697
ID: 1358283
Where is that at inprise? FAQ? Anyway will look at this immediately and let you know how it goes. Had a look at it here and it looks like it will do the job. Thanks Zif appreciate the help.

WESTY 8)
(Will most likely award the points as soon as I test it ok)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358284
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:westy100697
ID: 1358285
Zif,
    What you just gave me works fine. I will have to automate it though to give me the ability to modify more than one field at a time and will need to be able to do this without actually typing in the field description but this part should be fine now that I know what has been going wrong. Appreciate the help and here are the points and an A grading.
TA heaps.

WESTY
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358286
Hi westy,

Sorry for not looking earlier to your question, but I guess it slipped through the fingers. Good idea for posting that reminder.

Greetings, Zif.

Happy BDE programming.
0
 

Author Comment

by:westy100697
ID: 1358287
Zif,
    After I got this going I did a little more research as I kept getting " Invalid field descriptor" . I went back to the D3 help for TFields and starting reading then I went and bashed my head on the wall after reading  ".....is a zero based array." I have for the last couple of months been trying on and off to solve this and as it turned out I was initialising my loop with 1 instead of 0. Almost Comical EH!

WESTY (PS. Thanks again)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358288
westy, hope your head is ok again ;-). I guess, we all have this thing now and then... some almost everytime ... ;-). See you, Zif.
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question