Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Packing Paradox TTables in D3 Standard

Posted on 1998-09-06
6
Medium Priority
?
317 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
[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
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 400 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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