Board index » delphi » Modifying Paradox Field Types at Runtime

Modifying Paradox Field Types at Runtime

I'm trying to modify a Paradox field type at runtime. Specifically I want to
change the length of a string field from say 10 Characters to 20 Characters.
Can anyone shed some light on this. Thanks.

Regards
Gregory Sebastian

 

Re:Modifying Paradox Field Types at Runtime


On Mon, 20 Dec 1999 13:46:58 +0800, "Gregory Sebastian"

Quote
<bizs...@pacific.net.sg> wrote:
>I'm trying to modify a Paradox field type at runtime. Specifically I want to
>change the length of a string field from say 10 Characters to 20 Characters.
>Can anyone shed some light on this. Thanks.

Here's an improved version of an example that appears to be taken from
the Borland web site.  For your requirement, set the iLength field to
20:

type
  ChangeRec = packed record
    szName: DBINAME;
    iType: Word;
    iSubType: Word;
    iLength: SmallInt;
    iPrecision: SmallInt;
    end;

procedure ChangeField(Table: TTable; Field: TField; Rec: ChangeRec);
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;
  pFields, pCurField: pFLDDesc;
  pOp, pCurOp: pCROpType;
  ItrFld: Word;
begin
  // Initialize the pointers...
  pFields := nil;
  pOp := nil;
  // Make sure the table is open exclusively so we can restructure..
  if not Table.Active then
    raise EDatabaseError.Create('Table must be opened '+
      'to restructure');
  if not Table.Exclusive then
    raise EDatabaseError.Create('Table must be opened exclusively ' +
      'to restructure');
  // Set the cursor in physical translation mode
  Check(DbiSetProp(hDBIObj(Table.Handle), curxltMODE, Ord(xltNONE)));
  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));
  // Make sure the table is either Paradox, dBASE or FoxPro...
  if (Props.szTableType <> szPARADOX) and
     (Props.szTableType <> szDBASE) and
     (Props.szTableType <> szFOXPRO) then
    raise EDatabaseError.Create('Field altering can only occur on '+
      'Paradox, dBASE or FoxPro tables');
  try
    // Allocate memory for the field descriptor...
    pFields := AllocMem(Props.iFields * sizeof(FLDDesc));
    // Allocate memory for the operation descriptor...
    pOp := AllocMem(Props.iFields * sizeof(CROpType));
    // Null out the operations (= crNOOP)...
    FillChar(pOp^, Props.iFields * sizeof(CROpType), #0);
    // Set the pointer to the index in the operation descriptor to put
    // crMODIFY (means a modification to the structure)...
    pCurOp := pOp;
    Inc(pCurOp, Field.FieldNo - 1);
    pCurOp^ := crMODIFY;
    // Fill field descriptor with the existing field information...
    Check(DbiGetFieldDescs(Table.Handle, pFields));
    // Set pointer to the index in the field descriptor to make the
    // modifications to the field
    pCurField := pFields;
    Inc(pCurField, Field.FieldNo - 1);
    // If the szName portion of ChangeRec is used, change it...
    if (StrLen(Rec.szName) > 0) then
      StrCopy(pCurField^.szName, Rec.szName);
    // If the iType portion of ChangeRec is used, change it...
    if (Rec.iType > 0) then
      pCurField^.iFldType := Rec.iType;
    // If the iSubType portion of ChangeRec is used, change it...
    if (Rec.iSubType > 0) then
      pCurField^.iSubType := Rec.iSubType;
    // If the iLength portion of ChangeRec is used, change it...
    if (Rec.iLength > 0) then
      pCurField^.iUnits1 := Rec.iLength;
    // If the iPrecision portion of ChangeRec is used, change it...
    if (Rec.iPrecision > 0) then
      pCurField^.iUnits2 := Rec.iPrecision;
    pCurField := pFields;
    for ItrFld := 1 to Props.iFields do begin
      pCurField^.iFldNum := ItrFld;
      Inc(pCurField, 1);
    end;
    // Blank out the structure...
    FillChar(TableDesc, sizeof(TableDesc), #0);
    //  Get the database handle from the table's cursor handle...
    hDb := Table.DBHandle;
    // Put the table name in the table descriptor...
    StrPCopy(TableDesc.szTblName, Table.TableName);
    // Put the table type in the table descriptor...
    StrCopy(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 := Props.iFields;
    // 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;
    // Read restructure action...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, False));
  finally
    if (pFields <> nil) then
      FreeMem(pFields);
    if (pOp <> nil) then
      FreeMem(pOp);
  end;
end;

HTH,

Jan

Re:Modifying Paradox Field Types at Runtime


Quote
Gregory Sebastian wrote in message <83kf96$j...@forums.borland.com>...
>I'm trying to modify a Paradox field type at runtime. Specifically I want
to
>change the length of a string field from say 10 Characters to 20
Characters.
>Can anyone shed some light on this. Thanks.

Have a look at http://EZSoftware.tsx.org at EZ Data Install. It upgrades any
paradox table with changed field types, sizes, indexes and validity checks.

Re:Modifying Paradox Field Types at Runtime


Gregory Sebastian p1e ve zprv <83kf96$j...@forums.borland.com>.

Quote
>I'm trying to modify a Paradox field type at runtime. Specifically I want
to
>change the length of a string field from say 10 Characters to 20
Characters.
>Can anyone shed some light on this. Thanks.

In addition to Jan's solution (which should work for tables that are not
referential integrity masters), you can take a look at
http://www.rksolution.cz/delphi/pxupgr.htm
The utility performs Paradox database version upgrade under much
wider set of conditions (including referential integrity masters,
password protected tables etc.)
--
Roman
(please remove 'stopspam' in header when replying)
mail: i...@rksolution.cz
URL: www.rksolution.cz

Re:Modifying Paradox Field Types at Runtime


Quote
Gregory Sebastian wrote:

> I'm trying to modify a Paradox field type at runtime. Specifically I want to
> change the length of a string field from say 10 Characters to 20 Characters.
> Can anyone shed some light on this. Thanks.

> Regards
> Gregory Sebastian

We use Demian's TableScanner utility to create a 'MakeDB.pas' which we them
compile into the project - then we can restructure one or more tables with a
single line of code. (We also have to include his tblscn.dll with the exe.) We
use this for importing tables from previous release versions (if any tables'
structures have changed) and also for user-directed table repair from within the
app. Running his CheckTables function is very fast - we routinely handle 15-25
tables with up to thousands of records in under 10 seconds. 'Your mileage may
vary depending ...'

(*
 Table Scanner V4.00 - Released April, 1999
 Copyright 1997-1999 by Demian [dem...@gold.com.br]
 Code generated on Thursday, December 9, 1999 01:53 PM
 Requires TBLSCN16.DLL (Delphi 1) or TBLSCN.DLL (Delphi 2/3/4)

 CheckTables open array parameter:
 1. Boolean (REQUIRED): unconditional restructuring
 2. String (optional): target directory
 3. Pointer (optional): TScanEvent

 Full syntax: CheckTables([false,'C:\TEMP',@MyFunc])
 Minimum syntax: CheckTables([false])
*)
--
Pete Wason|"LWATPLOTG"|z...@stumpworld.c|hyn...@channel1.c|CUCUG|TA|PHX

Other Threads