Delphi Examples: DbiGetRintDesc

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiGetRintDesc

Return to chapter overview

Return and fill a TStringList with information on the referential integrity. This example uses the following input:

 fDbiGetRIntDesc(OrdersTbl, 1, MyList);

 

The function is:

function fDbiGetRIntDesc(Table: TTable; SeqNo: Word; RIntList: TStringList): RINTDesc;

var

 ThisTable, OtherTable: String;

 Props: CURProps;

 B: Byte;

begin

 ThisTable := '';

 OtherTable := '';

 FillChar(Result, sizeof(Result), #0);

 Check(DbiGetCursorProps(Table.Handle, Props));

if (Props.iRefIntChecks = 0) then

  raise EDatabaseError.Create('There are no referential integrity checks on this table');

 Check(DbiGetRIntDesc(Table.Handle, SeqNo, @Result));

if (RIntList <> nil) then begin

  with RIntList do begin

     Add(Format('NUMBER=%d', [Result.iRintNum]));

     Add(Format('NAME=%s', [Result.szRintName]));

    case Result.eType of

       rintMASTER: Add('TYPE=MASTER');

       rintDEPENDENT: Add('TYPE=DEPENDENT');

    else

       Add('TYPE=UNKNOWN');

    end;

     Add(Format('OTHER TABLE=%s', [Result.szTblName]));

    case Result.eModOp of

       rintRESTRICT: Add('MODIFY=RESTRICT');

       rintCASCADE: Add('MODIFY=CASCADE');

    else

       Add('MODIFY=UNKNOWN');

    end;

    case Result.eDelOp of

       rintRESTRICT: Add('DELETE=RESTRICT');

       rintCASCADE: Add('DELETE=CASCADE');

    else

       Add('DELETE=UNKNOWN');

    end;

     Add(Format('FIELD COUNT=%d', [Result.iFldCount]));

    for B := 0 to DBIMAXFLDSINKEY do begin

      if (Result.aiThisTabFld[B] <> 0) then begin

        if (B <> 0) then

           ThisTable := Format('%s, %d', [ThisTable, Result.aiThisTabFld[B]])

        else

           ThisTable := IntToStr(Result.aiThisTabFld[B]);

      end

      else

         Break;

    end;

     Add('FIELDS=' + ThisTable);

    for B := 0 to DBIMAXFLDSINKEY do begin

      if (Result.aiOthTabFld[B] <> 0) then begin

        if (B <> 0) then

           OtherTable := Format('%s, %d', [OtherTable, Result.aiOthTabFld[B]])

        else

           OtherTable := IntToStr(Result.aiOthTabFld[B]);

      end

      else

         Break;

    end;

     Add('FIELDS OTHER=' + OtherTable);

  end;

end;

end;