interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Query1: TQuery;
DBGrid1: TDBGrid;
PRocedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure Query1AfterOpen(DataSet: TDataSet);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
clf:array of Tcolor;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Query1.Active := False;
Query1.DatabaseName := 'DBDEMOS';
Query1.SQL.Add('select * from orders');
DataSource1.DataSet := Query1;
Dbgrid1.DataSource := DataSource1;
Dbgrid1.Align := alClient;
Query1.Active := True;
end;
procedure TForm1.Query1AfterOpen(DataSet: TDataSet);
var
i,aa:integer;
c:Tcolor;
begin
query1.DisableControls;
setlength(clf,query1.RecordCount);
query1.First;
i := Low(clf);
clf[i] := clRed;
c := clRed;
aa:=1;
while not query1.Eof do
begin
if (query1.RecNo - aa)>9 then
begin
aa := aa + 10;
if c = clRed then c:= clGreen
else c := clRed;
end;
clf[i] := c;
Inc(i);
query1.Next;
end;
query1.First;
query1.EnableControls;
end;
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
DBGrid1.Canvas.Brush.Color := clf[Dbgrid1.DataSource.DataSet.RecNo-1+Low(clf)];
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
end.
新闻热点
疑难解答