Delphi Examples: DbiGetObjFromObj

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiGetObjFromObj

Return to chapter overview

Show the driver name associated with the given parameters.

Delphi users will rarely need to call this function because most of this information is available through methods and properties of the TTable object.

 

//  Arguments:

//     hTmpDb:        Database handle

//     pszTableName:  Name of an existing table in the specified database

//     fDbiGetObjFromObj(hTmpDb, 'Employee.DB');  

procedure fDbiGetObjFromObj(hTmpDb: hDBIDb; TblName: String);

var

 hCursor: hDBICur;

 szName: array[0..DBIMAXPATHLEN] of char;

 nLen: Word;

 hObj: hDBIObj;

 rslt: DBIResult;

begin

 // Open the specified table

 Check(DbiOpenTable(hTmpDb, PChar(TblName), nil, nil, nil, 0,

   dbiREADONLY, dbiOPENSHARED, xltFIELD, True, nil, hCursor));

 // Retrieve driver handle given cursor handle

 Check(DbiGetObjFromObj(hDBIObj(hCursor), DBIOBJType(objDRIVER), hObj));

 // Display driver name associated with the object handle

 rslt := DbiGetProp(hObj, drvDRIVERTYPE, @szName, sizeof(DBIPATH),nLen);

if (rslt <> DBIERR_NONE) then

    Check(DbiCloseCursor(hCursor))

else

   ShowMessage('Drive type: '+szName);

 // Close table

 Check(DbiCloseCursor(hCursor));

end;

Return the driver name for the specified table

Return the driver name for the specified table. This example uses the following input:

 DriverStr := fDbiGetObjFromObj(hTmpDb, CustomerTbl);

 

The function is:

function fDbiGetObjFromObj(Table: TTable): String;

var

 nLen: Word;

 hObj: hDBIObj;

begin

 // Retrieve driver handle given cursor handle

 Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDRIVER, hObj));

 SetLength(Result, DBIMAXDRIVELEN);

 // Get driver name associated with the driver handle

 Check(DbiGetProp(hObj, drvDRIVERTYPE, PChar(Result), DBIMAXDRIVELEN, nLen));

 SetLength(Result, StrLen(PChar(Result)));

end;