Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

150pts CustomDBGrid Component

Posted on 2002-06-04
4
150 Views
Last Modified: 2010-04-04
0
Comment
Question by:third
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
bes67 earned 50 total points
ID: 7055531
Hi

Try this unit. This is JUST an example. PicDBGrid inherited from DBGrid and publish two properties Picture and PictureFieldName (to determine where to draw picture). Note that in the cell assotiated with this field just picture will be drawn, not the query data

unit PicDBGrid;

interface

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

type
  TPicDBGrid = class(TDBGrid)
  private
    { Private declarations }
    FPicture: TPicture;
    FPictureFieldName: string;
    procedure SetPicture(Value: TPicture);
  protected
    { Protected declarations }
    procedure DrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn;
                             State: TGridDrawState); override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Picture: TPicture read FPicture write SetPicture;
    property PictureFieldName: string read FPictureFieldName write FPictureFieldName;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TPicDBGrid]);
end;

{ TPicDBGrid }

constructor TPicDBGrid.Create(AOwner: TComponent);
begin
  inherited;
  FPicture := TPicture.Create;
end;

destructor TPicDBGrid.Destroy;
begin
  FPicture.Free;
  inherited;
end;

procedure TPicDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
  Column: TColumn; State: TGridDrawState);
begin
  inherited;
  if AnsiCompareText(Column.FieldName, PictureFieldName) = 0 then
    with Canvas do
    begin
      StretchDraw(Rect, FPicture.Bitmap);
    end;
end;

procedure TPicDBGrid.SetPicture(Value: TPicture);
begin
  FPicture.Assign(Value);
end;



end.
0
 
LVL 30

Author Comment

by:third
ID: 7055654

Great, that did it exactly what i want! could you post your answer on the link i've given above so i can give you all the points.

btw, i have additional request. could it be possible to add a property that will control the spaces between the rows.

i have tried the code below but i'm not so sure if that's the right way to do it. it destroys the appearance of the image (i.e. not proportionally sized).

procedure TPicDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
 Column: TColumn; State: TGridDrawState);
var
 OutRect : TRect;
begin
 inherited;
 if AnsiCompareText(Column.FieldName, PictureFieldName) = 0 then
   with Canvas do
   begin
     OutRect := Rect;
     InflateRect(OutRect,-2,-2);
     StretchDraw(OutRect, FPicture.Bitmap);
   end;
end;

thanks again! ;-)
0
 
LVL 1

Expert Comment

by:bes67
ID: 7056287
I have posted on given link and ... take a look on Indent property

0
 
LVL 30

Author Comment

by:third
ID: 7058161
here's the bonus... thanks again! ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 116
Can Viruses spread while transferring Binary data with Winsock 2 86
control image tags in a string ? 12 140
DBCtrlGrid, Delphi, Scroll 7 24
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question