Database

Scroll within a DBGrid

Here is tip how to scroll DBGrid private OldGridProc: TWndMethod; procedure GridWindowProc(var Message: TMessage); //… procedure TForm1.FormCreate(Sender: TObject); begin OldGridProc := DBGrid1.WindowProc; DBGrid1.WindowProc := GridWindowProc; end; procedure TForm1.GridWindowProc(var Message: TMessage); var Pos: SmallInt; begin OldGridProc(Message); […]

Database

Make a HTML and TXT report component

Make a HTML and TXT report component unit LittleReport; interface uses Windows, Messages, SysUtils, Classes, DB, Graphics; const FAuthor = ‘Simone Di Cicco’; FVersion = ‘1.0’; type TLittleReport = class(TComponent) protected FDataSet: TDataSet; FWidth: Integer; […]

Database

Create a Dataset lookup field at runtime

example: create lookup field (string, size: 50) at runtime with TStringField.Create(YourDataSet) do begin FieldName := ‘FieldName’; FieldKind := fkLookup; DataSet := YourDataSet; Name := DataSet.Name + FieldName; KeyFields := ‘YourKeyFields’; LookupDataSet := YourLookupDataSet; LookupKeyFields := […]

Database

Add a Row Number in your DBGrid

1. create new blank field in dbgrid 2. rename the title with ‘No’ 3. put this code in OnDrawColumncell 4. Now your Grid has a row number procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; […]

Database

Create an Access Database (2)

Create an Access Database (2) uses ComObj; procedure TForm1.Button1Click(Sender: TObject); var AccessApp: Variant; begin AccessApp := CreateOleObject(‘Access.Application’); AccessApp.NewCurrentDatabase(‘c:\111.mdb’); AccessApp := Unassigned; end;

Database

Color a specific (conditional) cell in a DBGrid

Color a specific (conditional) cell in a DBGrid procedure TFRM_Main.DBG_MainGetCellParams(Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; Highlight: Boolean); begin if (Field.AsString = ‘0’) and (Field.FullName = ‘LoadingAttn’) then begin Background := $00E69B00; AFont.Color […]