델파이 코리아의 팁 게시판에 있는 코드입니다.
{$R *.DFM}
type
TCustomDBGridCracker = class(TCustomDBGrid);
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with TCustomDBGridCracker(Sender) do
if DataLink.ActiveRecord = Row - 1 then
Canvas.Brush.Color := clGreen
else
Canvas.Brush.Color := clWhite;
TCustomDBGridCracker(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
저는 이거를 실행시키니 에러만 나거든여....
procedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const
괄호앞에 커서가 놓이면서 에러가 나여
왜 안되는지 어케해야 하는지 가르쳐 주세요
즐거운 하루되세요
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DBTables, Db, Grids, DBGrids, ComCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Database1: TDatabase;
Query1: TQuery;
DBGrid1: TDBGrid;
Query1G_CODE: TStringField;
Query1CODE: TStringField;
Query1CODENAME: TStringField;
Button1: TButton;
DBEdit1: TDBEdit;
procedure DBGridListDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure DrawField(const Value : String;
const Rect : TRect;
vCanvas : TCanvas;
vFont: TFont;
vAlignment: TAlignment;
FontStyle : TFontStyles;
FontColor : TColor;
BGColor : TColor);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DrawField(const Value : String;
const Rect : TRect;
vCanvas : TCanvas;
vFont: TFont;
vAlignment: TAlignment;
FontStyle : TFontStyles;
FontColor : TColor;
BGColor : TColor);
var
I : Integer;
begin
I := 0;
//First, fill in the background color of the cell
vCanvas.Brush.Color := BGColor;
vCanvas.FillRect(Rect);
//SetBkMode ensures that the background is transparent
SetBkMode(Canvas.Handle, TRANSPARENT);
//Set the passed font properties
vCanvas.Font := vFont;
vCanvas.Font.Color := FontColor;
vCanvas.Font.Style := vCanvas.Font.Style + FontStyle;
//Set Text Alignment
case vAlignment of
taRightJustify :
begin
SetTextAlign(vCanvas.Handle, TA_RIGHT);
I := Rect.Right - 2;
end;
taLeftJustify :
begin
SetTextAlign(vCanvas.Handle, TA_LEFT);
I := Rect.Left + 2;
end;
taCenter :
begin
SetTextAlign(vCanvas.Handle, TA_CENTER);
I := (Rect.Right + Rect.Left) DIV 2;
end;
end; { case }
//Draw the text
vCanvas.TextRect(Rect, I, Rect.Top + 2, Value);
SetTextAlign(vCanvas.Handle, TA_LEFT);
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with Sender as TDBGrid, DataSource.DataSet do
if FieldByName('CODENAME').AsString = DBEdit1.TEXT THEN //'ET1' then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [fsUnderline], //[fsBold],
clYellow, clBLACK);
end;
procedure TForm1.DBGridListDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
inherited;
with Sender as TDBGrid, DataSource.DataSet do
if FieldByName('CODENAME').AsString = DBEdit1.TEXT THEN //'ET1' then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [fsBold],
clYellow, clRed);
end;
end.