Welcome to Andrew home page about Delphi!


Hello, my name is Andrew. I have been using Delphi since version 3.0 (around 1997). I have designed this home page in order to share my experiences of Delphi here with other people.

1. Delphi tutorial

First of all i'd like to show first VCL component written five two years ago about. This database grid with one additional property (LinesPerRow). This property allow to diplay the memo fields values directly in the grid cells. I hope this tutorial will be useful and help you to create the another Db-aware VCL components.

unit MLinesDbGrid;

interface

uses
     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
     Grids, DBGrids, Db;

type
     TMLinesDbGrid = class(TDbGrid)
     private
     FLinesPerRow: Integer;
     procedure SetLinesPerRow (Value: Integer);
     protected
     procedure LayoutChanged; override;
     procedure DrawColumnCell(const Rect: TRect; DataCol: Integer;
     Column: TColumn; State: TGridDrawState); override;
     public
     constructor Create (AOwner: TComponent); override;
     published
     property LinesPerRow: Integer
     read FLinesPerRow write SetLinesPerRow
     default 1;
     end;

procedure Register;

implementation
//------------------------------------------------------------------------------
constructor TMLinesDbGrid.Create(AOwner: TComponent);
begin
     inherited Create(AOwner);
     FLinesPerRow := 1;
end;
//------------------------------------------------------------------------------
procedure TMLinesDbGrid.LayOutChanged;
var
     PixelsPerRow, PixelsTitle, I: Integer;
begin
     inherited LayOutChanged;
     Canvas.Font := Font;
     PixelsPerRow := Canvas.TextHeight('Wg') + 3;
     if dgRowLines in Options then
     Inc (PixelsPerRow, GridLineWidth);

     Canvas.Font := TitleFont;
     PixelsTitle := Canvas.TextHeight('Wg') + 4;
     if dgRowLines in Options then
     Inc (PixelsTitle, GridLineWidth);

     // set number of rows
     //RowCount := 1 + (Height - PixelsTitle) div
     // (PixelsPerRow * FLinesPerRow);

     // set the height of each row
     DefaultRowHeight := PixelsPerRow * FLinesPerRow;
     RowHeights [0] := PixelsTitle;
     for I := 1 to RowCount - 1 do
       RowHeights [I] := PixelsPerRow * FLinesPerRow;
end;
//------------------------------------------------------------------------------
procedure TMLinesDbGrid.DrawColumnCell(const Rect: TRect;
     DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
     Bmp: TBitmap;
     OutRect: TRect;
     I : Integer;
begin
     if FLinesPerRow = 1 then
       inherited DrawColumnCell(Rect, DataCol, Column, State)
     else
     begin
     If Assigned (onDrawColumnCell) then
     onDrawColumnCell(Self, Rect, DataCol, Column, State);
     // clear area
     Canvas.FillRect (Rect);
     // copy the rectangle
     OutRect := Rect;
     // restrict output
     InflateRect (OutRect, -2, -2);
     // output field data
     if (Column.Field is TGraphicField) {or (Column.Field is TBlobField)} then
     begin
     Bmp := TBitmap.Create;
     try
     Bmp.Assign (Column.Field);
     Canvas.StretchDraw (OutRect, Bmp);
     finally
     Bmp.Free;
     end;
     end
     else If (Column.Field is TMemoField) or (Column.Field is TStringField) then
     begin
     DrawText (Canvas.Handle,
     PChar (Column.Field.AsString),
     Length (Column.Field.AsString),
     OutRect, dt_WordBreak or dt_NoPrefix);

     end
     else // draw single line vertically centered
     DrawText (Canvas.Handle,
     PChar (Column.Field.DisplayText),
     Length (Column.Field.DisplayText),
     OutRect, {dt_vcenter or} dt_SingleLine or dt_NoPrefix);

     {DrawText (Canvas.Handle,
     PChar (Column.Field.AsString),
     Length (Column.Field.AsString),
     OutRect, dt_WordBreak or dt_NoPrefix) }
     end;
end;
//------------------------------------------------------------------------------
procedure TMLinesDbGrid.SetLinesPerRow(Value: Integer);
begin
     if Value <> FLinesPerRow then
     begin
     FLinesPerRow := Value;
     LayoutChanged;
     end;
end;
//------------------------------------------------------------------------------
procedure Register;
begin
     RegisterComponents('Data Controls', [TMLinesDbGrid]);
end;
//------------------------------------------------------------------------------
end.


2. My Delphi bookmarks

  • Delphi32.com
  • Delphi Super Page
  • Delphi Delhi
  • Delphi Resource Center
  • Borland Community
  • About Delphi Programming
  • DelphiNow.com


    3. My hobbies

    I like the table tennis :), the mountaineering with my friends. My best friend is Patrik and we are more than just friends. We are gays.
    Here you can find the some links concerning of my interests:

  • Delphi Pages
  • Torry's Delphi Page
  • DelphiSource.com
  • Delphi City

  • Queer Resources Directory
  • Pinkfinance.com
  • Men's Health Links
  • Community Links
  • Community central