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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormShow(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var Timg:array[0..9] of tbitmap;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
// creation du tableau de bitmap .. la taille est fonction du nombre
// d'image differente a afficher
for i:=0 to 9 do Timg[i]:=Tbitmap.Create;
end;
procedure TForm1.FormShow(Sender: TObject);
const Tc:array[0..9] of Tcolor=(clwhite,clYellow,clLime,clGreen,clBlue,clred,clmaroon,Clgray,claqua,clTeal);
var c,l,i: integer ;
begin
// ici je dessine les rectangles de couleur dans mes bitmaps (les images)
for i:=0 to 9 do
begin
Timg[i].Width:=12;
Timg[i].Height:=24;
Timg[i].canvas.brush.color:=Tc[i];
Timg[i].canvas.Pen.color:=Tc[i];
Timg[i].Canvas.Rectangle(0,0,Timg[i].Width,Timg[i].Height);
end;
// initalisation du tableau avec le bitmap n°0 tout blanc
for c:=0 to 9 do
for l:=0 to 9 do StringGrid1.Cells[C,L]:='0000';
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var img1:string[2];
img2:string[2];
Codeimg1:integer;
Codeimg2:integer;
begin
with StringGrid1.canvas do
begin
// n'affiche l'image que si le code correct (2x2 caracteres)
if length(StringGrid1.cells[Acol,Arow])=4 then
begin
// recupere le code pour image les deux 1er caracteres l'image1 et les deux derniers l'image 2
img1:=StringGrid1.cells[Acol,Arow][1]+StringGrid1.cells[Acol,Arow][2];
img2:=StringGrid1.cells[Acol,Arow][3]+StringGrid1.cells[Acol,Arow][4];
if Not TryStrToInt(img1,Codeimg1) then Codeimg1:=0;
if Not TryStrToInt(img2,Codeimg2) then Codeimg2:=0;
// affiche l'image en fonction du code, ce code est en fait l'emplacement dans le tableau de bitmap
Draw(Rect.Left,Rect.top,Timg[Codeimg1]);
Draw(Rect.Left+12,Rect.top,Timg[Codeimg2]);
end;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var i:integer;
begin
// destruction du tableau de bitmap quand je quitte
for i:=0 to 9 do Timg[i].free;
end;
end. |
Partager