Database

Select a random datarecord

Select a random datarecord procedure TForm1.FormCreate(Sender: TObject); begin Randomize; end; procedure TForm1.Button1Click(Sender: TObject); begin Table1.First; Table1.MoveBy(Random(Table1.RecordCount)); end;

Database

Add a password to a paradox table

Add a password to a paradox table uses Bde, SysUtils, dbtables, windows; function StrToOem(const AnsiStr: string): string; begin SetLength(Result, Length(AnsiStr)); if Length(Result) 0 then CharToOem(PChar(AnsiStr), PChar(Result)); end; function TablePasswort(var Table: TTable; password: string): Boolean; var […]

Database

BDE Error list

BDE Error list: $0000 (0) = Successful completion. $0021 (33) = System Error $0022 (34) = Object of Interest Not Found $0023 (35) = Physical Data Corruption $0024 (36) = I/O Related Error $0025 (37) […]

Database

Show a TTable’s deleted records

Show a TTable’s deleted records procedure DeletedRecords(Table: TTable; SioNo: Boolean); begin Table.DisableControls; try Check(DbiSetProp(hDBIObj(Table.Handle), curSOFTDELETEON, Longint(SioNo))); finally Table.EnableControls; end; Table.Refresh; end;

Database

Undelete a dBASE record

Undelete a dBASE record procedure RecordUndelete(aTable: TTable); begin aTable.UpdateCursorPos; try Check(DbiUndeleteRecord(aTable.Handle)); except ShowMessage(‘No undelete performed.’); end; end;

Database

Save a Formula One spreadsheet to a blob field

Save a Formula One spreadsheet to a blob field uses vcf1, dbtables; procedure SaveSpreadsheet(F1Book: TF1Book); var BlobStream: TBlobStream; MyBlob: HGlobal; pblob: Pointer; begin with Datamodule1.Query1 do begin Set8087CW($133f); try Application.ProcessMessages; F1Book.SaveWindowInfo; MyBlob := GlobalAlloc(GMEM_MOVEABLE, 2000); […]

Database

Remove a dbase index flag

Remove a dbase index flag function UnCheckIndex(FileDbf: string): Boolean; var Dbf: file; Car: Char; begin Result := T; AssignFile(Dbf, FileDbf); Car := #0; {$I-} Reset(Dbf, 1); if not ErrorIO(FileDbf, IoResult) then begin Seek(Dbf, 28); {Flag’s […]

Database

Pack a Table

Pack a Table Packs a Paradox table by calling the BDE DbiDoRestructure function. The TTable passed as the first parameter must be closed. The TDatabase passed as the second parameter must be connected. function dgPackParadoxTable(Tbl: […]

Database

Select all Fields in a DBGrid

Select all Fields in a DBGrid function GridSelectAll(Grid: TDBGrid): Longint; begin Result := 0; Grid.SelectedRows.Clear; with Grid.DataSource.DataSet do begin First; DisableControls; try while not EOF do begin Grid.SelectedRows.CurrentRowSelected := True; Inc(Result); Next; end; finally EnableControls; […]

Database

Extract the ODBC System Data Sources

Extract the ODBC System Data Sources uses Registry; procedure TForm1.Button1Click(Sender: TObject); var n: Integer; List: TStringList; Reg: TRegistry; begin Reg := TRegistry.Create; try Reg.RootKey := HKEY_CURRENT_USER; Reg.LazyWrite := False; Reg.OpenKey(‘Software\ODBC\ODBC.INI\ODBC Data Sources’, False); List := […]

Database

Accelerate database searches

Accelerate database searches type TForm1 = class(TForm) DataSource1: TDataSource; Table1: TTable; Button1: TButton; end; procedure TForm1.Button1Click(Sender: TObject); var SeekValue: string; begin Table1.DisableControls; Table1.FindKey([SeekValue]); Table1.EnableControls; end;

Database

Make an ADODB Connection using OLE-Automation

Make an ADODB Connection using OLE-Automation uses ComObj; function OpenConnection(ConnectionString: AnsiString): Integer; var ADODBConnection: OleVariant; begin ADODBConnection := CreateOleObject(‘ADODB.Connection’); ADODBConnection.CursorLocation := 3; // User client ADODBConnection.ConnectionString := ConnectionString; Result := 0; try ADODBConnection.Open; except Result […]

Database

Load all records at once into a Stringlist

{ Loading millions of records into a stringlist can be very slow } procedure TForm1.SlowLoadingIntoStringList(StringList: TStringList); begin StringList.Clear; with SourceTable do begin Open; DisableControls; try while not EOF do begin StringList.Add(FieldByName(‘OriginalData’).AsString); Next; end; finally EnableControls; […]

Database

Move Columns in a TDBGrid

Move Columns in a TDBGrid type THackAccess = class(TCustomGrid); { THackAccess Is needed because TCustomGrid.MoveColumn is protected and you can’t access it directly. } // In the implementation-Section: procedure MoveDBGridColumns(DBGrid: TDBGrid; FromColumn, ToColumn: Integer); begin […]

Database

Prevent Data Corruption

{ If a database or a table is local on a PC installed (Paradox or Dbase) and the BDE-setting “LOCAL SHARE” is FALSE, then changings are not stored immediatly but are kept in the memory. […]

Database

Export a TDataSet to a XML file

{Unit to export a dataset to XML} unit DS2XML; interface uses Classes, DB; procedure DatasetToXML(Dataset: TDataSet; FileName: string); implementation uses SysUtils; var SourceBuffer: PChar; procedure WriteString(Stream: TFileStream; s: string); begin StrPCopy(SourceBuffer, s); Stream.Write(SourceBuffer[0], StrLen(SourceBuffer)); end; […]

Database

Color a TDBGrid

// Function to color a DBGrid (declared as private) procedure TForm1.ColorGrid(dbgIn: TDBGrid; qryIn: TQuery; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var iValue: LongInt; begin // color only the first field if (DataCol […]

Database

Process selected rows in a TDBGrid

In the “Object Inspector” set your DBGrid’s Option for dgMultiSelect = True. The Grid_Edit function calls for each selected DBGrid-Row a data-processing function. Return value is the number of processed rows. function TForm1.Grid_Edit(dbgIn: TDBGrid; qryIn: […]

Database

Read an Access DB using ADO

// Read an MS-ACCESS Database (any versions) using ADO // Verify if it is an ACCESS MDB // Components Needed on the Application Form are: // TADOtable,TDataSource,TOpenDialog,TDBGrid,TBitBtn. // Date : 14/01/2002 // Author: Michael Casse. […]

Database

Duplicate a TTable

As we know, Paradox Tables consist in a table file and some corresponding index files there are many way to copy them: 1. Using TBatchMover (at DataAccess Pallete) with Mode : BatCopy But you can’t […]

Database

Get the ODBC datasource names

Get the ODBC datasource names uses Registry; procedure TForm1.GetDataSourceNames(System: Boolean); var reg: TRegistry; begin ListBox1.Items.Clear; reg := TRegistry.Create; try if System then reg.RootKey := HKEY_LOCAL_MACHINE else reg.RootKey := HKEY_CURRENT_USER; if reg.OpenKey(‘\Software\ODBC\ODBC.INI\ODBC Data Sources’, False) then […]

Database

Get infos about aliases

Here’s a demo to demonstrate how to get info about aliases in Delphi. First, create a new project with a listbox and 3 labels (called ListBox1, Label1, Label2, and Label3). Then add an OnCreate event […]

Database

Change the TDBNavigator images

Change the TDBNavigator images   procedure ChangeDBNavImage(DBnav: TDbNavigator); var i: Integer; tempGlyph: TBitmap; ExePath: string; begin ExePath := ExtractFilePath(Application.ExeName); tempGlyph := TBitmap.Create; try with DBNav do begin for i := 0 to ControlCount – 1 […]