Solved

Packing Paradox TTables in D3 Standard

Posted on 1998-09-06
6
308 Views
Last Modified: 2010-04-06
How do I pack and regenerate indexes on Paradox tables using Delphi 3 Standard edition. I know it can be done in Database Desktop but how do I achieve it at runtime.
I can't find any reference to it in the help files.

I'm probably missing something really simple but I'm tearing my hair out here.

Please help me people !!
0
Comment
Question by:elkiors
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 100 total points
ID: 1338775
From Borland Documenatation:
http://www.inprise.com/devsupport/bde/bdeapiex/dbidorestructure.html

Example 2: Pack a Paradox or dBASE table.

           This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
           This function will also regenerate all out-of-date indexes (maintained indexes).
           This example uses the following input:
           PackTable(Table1)
           The function is defined as follows:

           // Pack a Paradox or dBASE table
           // The table must be opened execlusively before calling this function...
           procedure PackTable(Table: TTable);
           var
             Props: CURProps;
             hDb: hDBIDb;
             TableDesc: CRTblDesc;

           begin
             // 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 pack');
             if Table.Exclusive = False then
               raise EDatabaseError.Create('Table must be opened exclusively to pack');

             // Get the table properties to determine table type...
             Check(DbiGetCursorProps(Table.Handle, Props));

             // If the table is a Paradox table, you must call DbiDoRestructure...
             if Props.szTableType = szPARADOX then
             begin
               // 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);
               // Set the Pack option in the table descriptor to TRUE...
               TableDesc.bPack := True;
               // Close the table so the restructure can complete...
               Table.Close;
               // Call DbiDoRestructure...
               Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
             end
             else
               // If the table is a dBASE table, simply call DbiPackTable...
               if Props.szTableType = szDBASE then
                 Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
               else
                 // Pack only works on PAradox or dBASE; nothing else...
                 raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +
                          'type to pack');

             Table.Open;
           end;
0
 

Author Comment

by:elkiors
ID: 1338776
Please bear with me while I check out your answer, I'm a little pushed for time for checking it out. Give me a couple of days and I'll Accept or Reject.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338777
OK, if you have problems then before the first Check(...
write:                                Check(dbiInit(Nil)); //initializing the BDE
and on the end write:       DbiExit;               //freening resources
0
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.

 

Author Comment

by:elkiors
ID: 1338778
Ronit:

I'm sorry but I can't get this to compile, if you could make this a stand alone unit that I can just add to my projects it would be great.

At the moment it seems to be stopping on var types declared at the front of the PackTable procedure, I've tried to do a search for them in the help files so that I can trace the standard units requirements but no luck so far. Unfortunately, I'm still a novice, so the really low-level stuff like this is a bit beyond me.

I've upped the points as much as I can to help you consider the extra bit of effort needed on your part

thanx in advance for all your help

regards

elkiors



unit dbPack;

interface

procedure PackTable(Table: TTable);

implementation

// This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
// This function will also regenerate all out-of-date indexes (maintained indexes).
// This example uses the following input:
// PackTable(Table1)
// The function is defined as follows:

// Pack a Paradox or dBASE table
// The table must be opened execlusively before calling this function...
procedure PackTable(Table: TTable);
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;

begin
  // 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 pack');
  if Table.Exclusive = False then raise EDatabaseError.Create('Table must be opened exclusively to pack');

  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));

  // If the table is a Paradox table, you must call DbiDoRestructure...
  if Props.szTableType = szPARADOX then
  begin
    // 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);
    // Set the Pack option in the table descriptor to TRUE...
    TableDesc.bPack := True;
    // Close the table so the restructure can complete...
    Table.Close;
    // Call DbiDoRestructure...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
  end
  else
    // If the table is a dBASE table, simply call DbiPackTable...
    if Props.szTableType = szDBASE then
      Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
    else
      // Pack only works on PAradox or dBASE; nothing else...
      raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' + 'type to pack');
        Table.Open;
end;

end.

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1338779
Did you add to the uses --->BDE, DBTables,DB?
0
 

Author Comment

by:elkiors
ID: 1338780
thanx ronit, just what i need
the final compilable unit is listed below so anyone else can use it without any need to modify it further.


---------------------------------
unit dbPack;

interface

uses BDE, DBTables, DB, sysutils;

procedure PackTable(Table: TTable);

implementation

// This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
// This function will also regenerate all out-of-date indexes (maintained indexes).
// This example uses the following input:
// PackTable(Table1)
// The function is defined as follows:

// Pack a Paradox or dBASE table
// The table must be opened execlusively before calling this function...
procedure PackTable(Table: TTable);
var
  Props: CURProps;
  hDb: hDBIDb;
  TableDesc: CRTblDesc;

begin
  // 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 pack');
  if Table.Exclusive = False then raise EDatabaseError.Create('Table must be opened exclusively to pack');

  // Get the table properties to determine table type...
  Check(DbiGetCursorProps(Table.Handle, Props));

  // If the table is a Paradox table, you must call DbiDoRestructure...
  if Props.szTableType = szPARADOX then
  begin
    // 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);
    // Set the Pack option in the table descriptor to TRUE...
    TableDesc.bPack := True;
    // Close the table so the restructure can complete...
    Table.Close;
    // Call DbiDoRestructure...
    Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
  end
  else
    // If the table is a dBASE table, simply call DbiPackTable...
    if Props.szTableType = szDBASE then
      Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
    else
      // Pack only works on PAradox or dBASE; nothing else...
      raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' + 'type to pack');
        Table.Open;
end;

end.
----------------------------------------------------

thanks once again,

enjoy the points,

c u on another thread.

elkiors (Darren)

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
Activex loadlibrary and show parented form issue 6 285
How to use Hashing sha1 in Delphi 2010 4 198
Newbie Thread Programming 1 138
JAudiorecorder record freezing the app 29 59
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
A short film showing how OnPage and Connectwise integration works.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

943 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

6 Experts available now in Live!

Get 1:1 Help Now