唾手可得的20分!(20分)

  • 主题发起人 主题发起人 boye
  • 开始时间 开始时间
B

boye

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyDBGrid = class(TCustomDBGrid)
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
//上段编译出错,面向对象才开始学,什么都不懂,先奉上20分再说
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
 

TMyDBGrid = class(TCustomDBGrid)
public //这里
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
end;

另外你的实现部分在哪儿?
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyDBGrid = class(TCustomDBGrid)
public
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
//上段编译出错,面向对象才开始学,什么都不懂,先奉上20分再说
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;
if (acol<1) or (arow<1) then exit;
if {(gdFixed in AState) and }([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then
begin
self.Canvas.Pen.Color:=clred;
InflateRect(ARect, 1, 0);
canvas.Polyline([point(arect.Left,arect.Top),point(arect.Left,arect.Bottom),point(arect.Right,arect.Bottom),point(arect.Right,arect.Top)]);
end;

end;
end.
 
uses Grids, DBGrids;
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Grids, DBGrids;;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyDBGrid = class(TCustomDBGrid)
public
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
//上段编译出错,面向对象才开始学,什么都不懂,先奉上20分再说
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;
if (acol<1) or (arow<1) then exit;
if {(gdFixed in AState) and }([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then
begin
self.Canvas.Pen.Color:=clred;
InflateRect(ARect, 1, 0);
canvas.Polyline([point(arect.Left,arect.Top),point(arect.Left,arect.Bottom),point(arect.Right,arect.Bottom),point(arect.Right,arect.Top)]);
end;

end;
end.
 
你的代码不全,刚刚明明有DBGrid1: TDBGrid;,uses里却少了Grids, DBGrids;
现在Grids, DBGrids;; <-多了一个分号
而且procedure FormCreate(Sender: TObject);的实现部分在哪儿?
 
简单来说,当申明一个新类怎样加进去过程,(I am fool!)
 
似乎没有问题。那一行报错了,报什么错?
 
[Error] Unit1.pas(19): Unsatisfied forward or external declaration: 'TMyDBGrid.DrawCell'
 
我用D5,下面的代码没有问题,你可以新建一个工程试试:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;


TMyDBGrid = class(TCustomDBGrid)
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
end;


var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;
if (acol<1) or (arow<1) then exit;
if {(gdFixed in AState) and }([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then
begin
self.Canvas.Pen.Color:=clred;
InflateRect(ARect, 1, 0);
canvas.Polyline([point(arect.Left,arect.Top),point(arect.Left,arect.Bottom),point(arect.Right,arect.Bottom),point(arect.Right,arect.Top)]);
end;

end;

end.
 
接受答案了.
 
后退
顶部