Board index » delphi » Primary key fields of a Paradox Table

Primary key fields of a Paradox Table

Does anyone know how to retrieve the primary key field(s) of a given
paradox table, using delphi??
 

Re:Primary key fields of a Paradox Table


On 16 Jan 1996 20:31:51 GMT, h...@central.co.nz (Chris O'Neill) wrote:

Quote
>Does anyone know how to retrieve the primary key field(s) of a given
>paradox table, using delphi??

You could iterate through the array of index definitions contained in the
TIndexDefs object. Each index definition in the array, of type TIndexDef,
has a Fields and an Options property. You would then need to iterate
through the TIndexDef objects until you arrive at the one that has the
TIndexOption ixPrimary in the Options property. The Fields property of that
TIndexDef object will contain the list of fields (or only one) that
comprise the primary index. For example:

  procedure TForm1.Button1Click(Sender: TObject);
  var
    i: Integer;
  begin
    i := 0;
    with Table1.IndexDefs do begin
      Update;
      if Count > 0 then begin
        while (i <= Count - 1) and not (ixPrimary in Items[i].Options) do
          Inc(i);
        ShowMessage('Primary index field(s): ' + Items[i].Fields);
      end
      else
        ShowMessage('No indexes');
    end;
  end;

**************************************************************************
Steve Koterski                    "Knowledge advances by steps, and not by
Product Group Manager             leaps."
Delphi Technical Support                       -- Lord Macaulay, 1800-1859
Borland International, Inc.

Other Threads