1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids;
type
TForm1 = class(TForm)
Grid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure Grid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
private
{ Déclarations privées }
public
{ Déclarations publiques }
procedure RandomGrid;
end;
var
Form1: TForm1;
function RandomStr (aLen: Integer): String;
implementation
{$R *.dfm}
// just for the test
function RandomStr (aLen: Integer): String;
var i: Integer;
begin
SetLength(result, aLen);
for i := 1 to aLen do
result[i] := Chr(Random(26) +65);
end;
procedure TForm1.RandomGrid;
var i: Integer;
begin
for i := 0 to Grid1.RowCount-1 do
begin
Grid1.Cells[0, i] := RandomStr(50);
if i mod 6 <> 0 then
Grid1.Cells[1, i] := Grid1.Cells[0, i]
else
Grid1.Cells[1, i] := 'à mettre en rouge';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Grid1.Width := 1024;
Grid1.ColCount := 2;
Grid1.RowCount := 1000;
Grid1.FixedCols := 0;
Grid1.FixedRows := 0;
Grid1.DefaultColWidth := 500;
RandomGrid;
end;
procedure TForm1.Grid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (aCol=1) and (Grid1.Cells[0, aRow] <> Grid1.Cells[1, aRow] ) then
with Grid1 do begin
Canvas.Rectangle(Rect);
Canvas.Font.Color := clRed;
Canvas.TextOut(Rect.Left, Rect.Top, Cells[0, aRow]);
end;
end;
end. |
Partager