Solved

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

Posted on 1998-07-21
7
308 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
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 250 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 46
Dev Express grid collapse 2 39
SCCM2012 sp2 CU3 cant see boot images missing tabs 3 60
Reconfigure Delphi Install? 2 47
Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now