Rx BDE Utilities

RX Library

Control Name Unit Class
BDE Utilities BdeUtils TDBLocate

Description:
Use TDBLocate to search a BDE-dataset specified by DataSet property for a specific record and position the cursor on it.

After setting DataSet property you can call Locate method which has parameter KeyField specified field name on which to search.

When you search on non-BDE data source, use TLocateObject class instead.

TDBLocate uses the fastest possible method to locate matching records. If DataSet specifies the TTable object and the search field is a key field and the IndexSwitch property is True, TDBLocate uses the index. Otherwise TDBLocate creates a filter for the search if applicable or use full search throw dataset otherwise.

NOTE. In Delphi 2.0 or higher you can use standard TDataSet.Locate method instead.


Property DataSet
Declaration: DataSet: TDataSet;

Specifies the dataset (table or query) for which Locate method will search for specified value. Set this property and IndexSwitch property to appropriate values before call Locate method.


Routine AsyncQrySupported
Declaration: function AsyncQrySupported(Database: TDatabase): Boolean;

Returns True if database driver specified by Database parameter supports asynchronous query execution. In 32-bit Delphi versions you can use OnServerYield event when True returned by AsyncQrySupported (for example, to break query execution in multi-threaded application). Currently, only Sybase driver supports asynchronous query execution.

AsyncQrySupported example:

When you execute your queries in separate thread, you can set OnServerYield event handler, for example, to end query processing.

You can check database for supporting yields control during query processing to enable or disable appropriate menu item:

CancelQueryItem.Visible := AsyncQrySupported(Database);


Routine CheckOpen
Declaration: function CheckOpen(Status: DBIResult): Boolean;

Checks the result of a call to the Borland Database Engine (BDE). Call CheckOpen to determine if a call to the BDE returns an error when an attempt is made to access a table. Status is the return result of a previous call to the BDE. CheckOpen returns True if there is access is successful. If Status indicates insufficient table rights when accessing a Paradox table, CheckOpen calls the database session’s GetPassword method to prompt the user for a password. If the dialog is successful, CheckOpen returns True. Otherwise CheckOpen returns False, indicating that dataset access failed.

> CheckOpen example:

function TFieldList.CreateHandle: HDBICur;
var
__STableName: PChar;
begin
__STableName := StrAlloc(Length(FTableName) + 1);
__try
____while not CheckOpen(DbiOpenFieldList(DBHandle, AnsiToNative(DBLocale,
______FTableName, STableName, Length(FTableName)), nil, False, Result)) do
____{Retry};
__finally
____StrDispose(STableName);
__end;
end;


Routine ConvertStringToLogicType
Declaration: procedure ConvertStringToLogicType(Locale: TLocale; FldLogicType: Integer; FldSize: Word; const FldName, Value: String; Buffer: Pointer);

ConvertStringToLogicType translates string specified by Value parameter into BDE logical type specified by FldLogicType. You can use translated value when you call BDE API functions directly.

You must allocate memory for Buffer to retrieve translated value. FldSize parameter specifies the maximum number of bytes to copy to the buffer.

ConvertStringToLogicType example:

var DataSet: TDataSet; Fld: TField; Buffer: Pointer; FldName: string;
begin
__...
__Fld := DataSet.FieldByName(FldName);
__GetMem(Buffer, Fld.DataSize);
__try
____ConvertStringToLogicType(DataSet.Locale, FieldLogicMap(Fld.DataType),
______Fld.DataSize, FldName, Value, Buffer);
____{ use the value in Buffer }
__finally
____FreeMem(Buffer, Fld.DataSize);
__end;
end;


Routine CurrentRecordDeleted
Declaration: function CurrentRecordDeleted(DataSet: TBDEDataSet): Boolean;

Determines if the current record of DataSet is deleted. Applicable only when soft delete is supported (dBASE and FoxPro only) and soft deletes is set to True by calling DatSetShowDeleted procedure.

CurrentRecordDeleted example:

if CurrentRecordDeleted(Table1) then
begin
__{ undelete record }
end;


Routine DataSetFindValue
Declaration: function DataSetFindValue(DataSet: TDataSet; const Value, FieldName: string): Boolean;

Searches the dataset for a specified record and makes that record the current record.

Call DataSetFindValue to search a dataset for a specific record and position the cursor on it. FieldName is a string containing a field name on which to search. Value is a value to match in the key field.

DataSetFindValue returns True if it finds a matching record, and makes that record the current one. Otherwise DataSetFindValue returns False.

DataSetFindValue example:

var DataSet: TDataSet; FieldName: string; Found: Boolean;
begin
__...
__Found := DataSetFindValue(DataSet, DataSet.FieldByName(FieldName).AsString, FieldName);
__if not Found then
____MessageDlg('Record not found', mtError, [mbOk], 0);
end;


Routine DataSetPositionStr
Declaration: function DataSetPositionStr(DataSet: TDataSet): string;

Retrieves string with current record number and full records count in DataSet in following format:
<record_no> : <record_count>.

This function is supported for Paradox and DBase drivers only.

DataSetPositionStr example:

procedure TMDIChild.DataSource1DataChange(Sender: TObject; Field: TField);
begin
__Panel1.Caption := DataSetPositionStr(DataSource1.DataSet);
end;


Routine DataSetRecNo
Declaration: function DataSetRecNo(DataSet: TDataSet): Longint;

This function retrieves the sequence (for Paradox and In-Memory tables) or physical (for DBase tables) number of the current record in the dataset DataSet. Applications might use this function with RecordCount property to iterate through all the records in a dataset, though typically record iteration is handled with calls to First, Last, MoveBy, Next, and Prior.

DataSetRecNo example:

RecNo := DataSetRecNo(Table1);


Routine DataSetShowDeleted
Declaration: procedure DataSetShowDeleted(DataSet: TBDEDataSet; Show: Boolean);

Toggles mode to show or hide deleted records in DataSet. Applicable only when soft delete is supported (dBASE and FoxPro only).

DataSetShowDeleted example:
DataSetShowDeleted(Table1, True);


Routine DeleteRange
Declaration: procedure DeleteRange(Table: TTable; IndexFields: array of const; FieldValues: array of const);

Deletes from Table all records specified by the key values FieldValues. Table must have an index on fields specified by IndexFields parameters.

DeleteRange example:
DeleteRange(Table1, ['ORDER_ID', 'CUSTOMER_NO'], [1, 255]);


Routine ExecuteQuery
Declaration: procedure ExecuteQuery(const DbName, QueryText: string);

Executes the SQL statement QueryText in the database specified by DbName parameter.

ExecuteQuery example:
ExecuteQuery('DBDEMOS', 'DELETE FROM CUSTOMER WHERE CustNo = 2135');


Routine ExportDataSet
Declaration: procedure ExportDataSet(Source: TDataSet; DestTable: TTable; TableType: TTableType; const AsciiCharSet: string; AsciiDelimited: Boolean; MaxRecordCount: Longint);

This procedure exports data from data source specified by Source parameter to the table specified by DestTable parameter. Function create the destination table based on the structure of the source data set. If the destination already exists, the function will delete it, and replace it with the new copy of the source.

For export into ASCII-format you can specify destination character set by AsciiCharSet parameter and fixed or delimited (varying) format by AsciiDelimited parameter. RecordCount parameter specifies the maximum number of records that are exported to the destination table when function is called. If zero, all records are added, beginning with the first record in Source.

ExportDataSet example:
var SourceDataSet: TDataSet; DestName, CharSet: string;
begin
__{...}
__if (SourceDataSet <> nil) then
__begin
____if SourceDataSet.Active then
______SourceDataSet.CheckBrowseMode;
____if (SourceDataSet is TTable) then
______DestName := ExtractFileName(TTable(SourceDataSet).TableName)
____else begin
______if not SourceDataSet.Active then DBError(SDataSetClosed);
________DestName := 'Query';
____end;
____DestName := ChangeFileExt(DestName, '.TXT');
__end;
__DestTable.TableName := DestName;
__ExportDataSet(SourceDataSet, DestTable, ttASCII, 'db866ru0', True, 0);
__MessageDlg(Format('Table %s successfully created.', [DestTable.TableName]),
____mtInformation, [mbOk], 0);
end;


Routine FetchAllRecords
Declaration: procedure FetchAllRecords(DataSet: TDataSet);

The FetchAllRecords procedure, when used with a query against a server database, forces the server to release all intermediate locks and reads the entire result set.

In Delphi 2.x or higher, use TDataset.FetchAll method instead.

FetchAllRecords example:

__Query1.Open;
__try
____FetchAllRecords(Query1);
____{ working with query result set }
__finally
____Query1.Close;
__end;


Routine FieldLogicMap
Declaration: function FieldLogicMap(FldType: TFieldType): Integer;

Returns BDE logical type identifier for the specified Delphi database field type.

FieldLogicMap example:
var
__I: Integer;
__Fld: TField;
begin
__...
__I := FieldLogicMap(Fld.DataType);
end;


Routine GetAliasPath
Declaration: function GetAliasPath(const AliasName: string): string;

Retrieves physical path for BDE alias specified by AliasName parameter. If specified database is SQL-bases database, the function returns server name as result.

> GetAliasPath example:
...
S := Format('Database path: %s', GetAliasPath(Database.AliasName));
...


Routine GetBDEDirectory
Declaration: function GetBDEDirectory: string;

Retrieves the path of the Borland Database Engine (BDE) directory. The BDE directory contains all BDE DLLs.

> GetBDEDirectory example:
ShowMessage(Format('BDI installed at %s', [GetBDEDirectory]));


Routine InitRSRun
Declaration: procedure InitRSRun(Database: TDatabase; const ConName: string; ConType: Integer; const ConServer: string);

Initializes Report Smith runtime by updating RPTSMITH.CON file.

ConName parameter specifies connection name. You can use empty string as this parameter to use application EXE-name as connection name. ConType is a connection type, defined in REPORT.PAS unit (i.e. ctIDAPIDBase). ConServer specifies server name, for example, 'PARADOX' or 'IBLOCAL'.

InitRSRun example:

procedure TMainForm.FormCreate(Sender: TObject);
begin
__InitRSRUN(Database, '', ctIDAPIParadox, 'PARADOX');
end;


Routine IsBookmarkStable
Declaration: function IsBookmarkStable(DataSet: TDataSet): Boolean;

Return True, if specified DataSet supports stable bookmarks. Stable bookmarks are those that remain unchanged after another user has modified the table. For example, return value is True for Paradox tables having a primary key, but False for Paradox heap tables.

IsBookmarkStable example:

BM := Table1.GetBookmark;
try
__{...}
__if IsBookmarkStable(Table1) then
____SetToBookmark(Table1, BM); { no exceptions raised }
__finally
____Table1.FreeBookmark(BM);
end;


Routine PackTable
Declaration: procedure PackTable(Table: TTable);

Packs the specified table, i.e deletes unused records from a Paradox or dBase table. This function does not work with SQL databases.

PackTable example:

PackTable(Table1);


Routine RestoreIndex
Declaration: procedure RestoreIndex(Table: TTable);

Restores TTable.IndexFieldNames property after calling SetIndex procedure. It's important to use SetIndex and RestoreIndex in conjunction. > RestoreIndex example:

SetIndex(Table1, 'NAME');

try
__...
finally
__RestoreIndex(Table1);
end;


Routine SetIndex
Declaration: procedure SetIndex(Table: TTable; const IndexFieldNames: string);

Use SetIndex specify an alternative index for a table by setting IndexFieldNames property. Use this procedure only with RestoreIndex:

SetIndex(Table1, 'NAME');
try
__...
finally
__RestoreIndex(Table1);
end;

SetIndex example:

SetIndex(Table1, 'NAME');
try
__...
finally
__RestoreIndex(Table1);
end;


Routine SetToBookmark
Declaration: function SetToBookmark(ADataSet: TDataSet; ABookmark: TBookmark): Boolean;

Returns dataset specified by the ADataSet parameter to a bookmark previously created by
GetBookmark method. SetToBookmark returns True if the call was successful, otherwise it retuqrns False. Note: If the bookmark is unstable, the cursor may be in an unexpected position.

SetToBookmark example:
BM := Table1.GetBookmark;
try
__{...}
__SetToBookmark(Table1, BM); { no exceptions raised }
finally
__Table1.FreeBookmark(BM);
end;


Routine TransActive
Declaration: function TransActive(Database: TDatabase): Boolean;

Indicates whether a database transaction is in progress or not. Use this function to determine if a database transaction is currently in progress. Return value is True if a transaction is in progress, False otherwise.

TransActive example:
if TransActive(Database) then
__Database.Commit;


Index Page | About | Download
Creation Date: 4 Feb 1998 | Last Update: 16 Mar 2000