unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, Menus, db, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    ColorsPopupMenu: TPopupMenu;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    Panel1: TPanel;
    Button1: TButton;
    procedure N13Click(Sender: TObject);
    procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses ADOConEd, DataModuleUnit;

{$R *.dfm}

procedure TForm1.N13Click(Sender: TObject);
const
 MenuColors: array[0..5] of TColor =(clBlack, clRed,
       clGreen, clYellow, clBlue, clPurple);
begin
 DataModule1.ADOTable1.Edit;

 DataModule1.ADOTable1Color.AsString:=
    ColorToString(MenuColors[TMenuItem(Sender).Tag]);

 DataModule1.ADOTable1.Post;
end;

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
 try
  DBGrid1.Canvas.Font.Style:=[];
  if (gdSelected in State) or (gdFocused in State)then
   begin
    DBGrid1.Canvas.Brush.Color:=clHighLight;
    DBGrid1.Canvas.Font.Color:=clWhite;
   end
  else
   begin
    DBGrid1.Canvas.Brush.Color:=clWhite;
    DBGrid1.Canvas.Font.Color:=clBlack;
    if DataModule1.ADOTable1Color.AsString<>'' then
     DBGrid1.Canvas.Font.Color:=
        StringToColor(DataModule1.ADOTable1Color.AsString);
   end;
  DBGrid1.Canvas.FillRect(Rect);
  DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top, Field.AsString);
 except
  DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top, Field.AsString);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 DataModule1.ADOConnection1.Close;
 if EditConnectionString(DataModule1.ADOConnection1) then
  begin
   DataModule1.ADOConnection1.Connected:=true;
   DataModule1.ADOTable1.Active:=true;
  end;
end;

end.
