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
   | {La déclaration}
type
  TClassAddOn = class(TObject)
     private
       Selected : Boolean;
     public
       ID       : string[20];
       CellColor  : TColor;
   //  constructor Create(???); virtual;
    end; 
 
[...]
 
{L'initialisation}
procedure TForm1.FormCreate(Sender: TObject);
var
  iCol, iRow : integer;   
begin                            
 with SG do //La StringGrid
   for iRow := 0 to RowCount -1 do
    for iCol := 0 to ColCount -1 do begin
     if TClassAddOn(Objects[iCol,iRow]) = nil then Objects[iCol,iRow] := TClassAddOn.Create();
      TClassAddOn(Objects[iCol,iRow]).CellColor := clWindow;
    end;   
[...]
end;
 
{Une affectation}
procedure TForm1.SGMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  iCol, iRow: Longint;
begin
  with SG do begin
    MouseToCell(X, Y, iCol, iRow);
    if iRow = 0 then exit;
    if (ssLeft in Shift) then begin
     Cells[iCol,iRow] := sgEMC.Cells[EMmatCol,sgEMC.Row]+LineEnding+sgEMC.Cells[EMEnsCol,sgEMC.Row];
     TClassAddOn(Objects[iCol,iRow]).CellColor  := StringToColor(sgEMC.Cells[EMhexCol,sgEMC.Row]);
    end;
    if (ssRight in Shift) then begin
      Cells[iCol,iRow] := '';
      TClassAddOn(Objects[iCol,iRow]).CellColor  := clWindow;
    end;
  end;
end;  
 
{Une lecture}
procedure TForm1.SGPrepareCanvas(sender: TObject; aCol, aRow: Integer;
  aState: TGridDrawState);
begin
  with SG do begin
   if (aRow =0) and (aCol =0) then
    Canvas.Font.Color:= clRed;
    if ARow = 5 then  
      Canvas.Brush.Color := clBtnFace;
 
    if (aCol > 0) and (aRow > 0) and (aRow <> 5) then begin
      Canvas.Brush.Color :=  TClassAddOn(Objects[aCol,aRow]).CellColor;
    end;
  end;
end; | 
Partager