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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| private
{ Déclarations privées }
// Transfert des variables globales privées en variables privées de la fiche
// cf. remarque de @popo
SG, LastRow: Integer;
FCorrec: Boolean;
GrOpNor,GrOpEdi: set of TGridOption;
LastLibel: string;
//...
procedure TEssaiFiche.FormActivate(Sender: TObject);
begin
GrOpNor := [goFixedHorzLine, goFixedVertLine, goVertLine, goHorzLine, goRowSelect];
GrOpEdi := [goFixedHorzLine, goFixedVertLine, goVertLine, goHorzLine, goEditing];
with SG1 do
begin
Options := grOpNor;
Cells[0,1] := '1WWWW';
Cells[0,2] := '1XXXX';
Cells[0,3] := '1YYYY';
Cells[0,4] := '1ZZZZ';
end;
with SG2 do
begin
Options := grOpNor;
Cells[0,1] := '2WWWW';
Cells[0,2] := '2XXXX';
Cells[0,3] := '2YYYY';
Cells[0,4] := '2ZZZZ';
end;
// Pour que la fiche soit initialement dans un état cohérent !
BOK.Visible := False;
BAnnul.Visible := False;
RGCorrec.Visible := False;
RGCorrec.ItemIndex := -1;
end;
procedure TEssaiFiche.SG1DrawCell(Sender: TObject; ACol,
ARow: integer; Rect: TRect; State: TGridDrawState);
var
C: TColor;
Info: String;
begin
// Inutile !
// if FCorrec then
// Exit;
// On sait que Sender est du type TStringGrid, autant utiliser le transtypage direct, plus rapide
with TStringGrid(Sender) do
begin
// Je crois qu'ici, vous avez perdu de vue vos spécifications...
// if (BOK.Visible) and (SG = 1) then
// C := clAqua
// else if gdFixed in State then
// C := clBtnFace
// else if (SG = 1) and ((not Enabled) and (gdSelected in State)) then
// C := clAqua
// else if not Focused then
// C := clWhite
// else if (gdFocused in State) or (gdSelected in State) then
// C := clBlue
// else
// C := clWhite;
// 3 cas possibles : colonne fixe, sélectionnée ou autre
if gdFixed in State then
C := clBtnFace
else if gdSelected in State then
C := clAqua
else
C := clWhite;
//
Canvas.Brush.Color := C;
Canvas.FillRect(Rect);
Canvas.Font.Assign(Font);
// Inutile !
// if C = clBlue then
// Canvas.Font.Color := clWhite;
Canvas.TextOut(Rect.Left, Rect.Top, Cells[ACol,ARow]);
end;
end;
procedure TEssaiFiche.SG1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
var
Point: TPoint;
C, R: Integer;
begin
// Inutile !
// if RGCorrec.Visible then
// SG1.Row := LastRow;
Point := Mouse.CursorPos;
if Button = mbRight then
begin
SG := 1;
with TStringGrid(Sender) do
begin
// Inutile, vous allez désactiver le composant juste après !
// if not Focused then
// SetFocus;
MouseToCell(X, Y, C, R);
Col := C;
Row := R;
SG1.Row := R;
end;
RGCorrec.Visible := True;
SG1.Enabled := False;
SG2.Enabled := False;
end;
end;
procedure TEssaiFiche.RGCorrecClick(Sender: TObject);
begin
if RGCorrec.ItemIndex = 0 then
begin
// Code appelé quelque soient les cas, déplacé en fin de procédure
// RGCorrec.Visible := False;
// RGCorrec.ItemIndex := -1;
FCorrec := True;
BOK.Visible := True;
BAnnul.Visible := True;
case SG of
1: begin
LastRow := SG1.Row;
LastLibel := SG1.Cells[0, SG1.Row];
SG1.Enabled := True;
SG1.Options := GrOpEdi;
SG1.SetFocus;
// Donner le focus, c'est bien, passer en mode édition, c'est mieux !
SG1.EditorMode := True;
end;
2: begin
LastRow := SG2.Row;
LastLibel := SG2.Cells[0, SG2.Row];
SG2.Enabled := True;
SG2.Options := GrOpEdi;
SG2.SetFocus;
SG2.EditorMode := True;
end;
end;
end
else
begin
SG1.Enabled := True;
SG2.Enabled := True;
// RGCorrec.Visible := False;
case SG of
1: SG1.SetFocus;
2: SG2.SetFocus;
end;
// RGCorrec.ItemIndex := -1;
end;
RGCorrec.Visible := False;
RGCorrec.ItemIndex := -1;
end;
procedure TEssaiFiche.BOKClick(Sender: TObject);
begin
SG1.Enabled := True;
SG2.Enabled := True;
BOK.Visible := False;
BAnnul.Visible := False;
FCorrec := False;
case SG of
1: begin
if SG1.Cells[0, SG1.Row] = '' then
begin
MessageDlg('L''intitulé n''est pas spécifié.', mtError, [mbOK], 0);
SG1.Cells[0, SG1.Row] := LastLibel;
SG1.SetFocus;
Exit;
end;
SG1.Options := grOpNor;
SG1.SetFocus;
end;
2: begin
if SG2.Cells[0, SG2.Row] = '' then
begin
MessageDlg('L''intitulé n''est pas spécifié.', mtError, [mbOK], 0);
SG2.Cells[0, SG2.Row] := LastLibel;
SG2.SetFocus;
Exit;
end;
SG2.Options := grOpNor;
SG2.SetFocus;
end;
end;
LastLibel := '';
BOK.Visible := False;
BAnnul.Visible := False;
end;
procedure TEssaiFiche.BAnnulClick(Sender: TObject);
begin
FCorrec := False;
SG1.Enabled := True;
SG2.Enabled := True;
BOK.Visible := False;
BAnnul.Visible := False;
case SG of
1: begin
SG1.Options := grOpNor;
SG1.Cells[0, LastRow] := LastLibel;
SG1.SetFocus;
end;
2: begin
SG2.Options := grOpNor;
SG2.Cells[0, LastRow] := LastLibel;
SG2.SetFocus;
end;
end;
LastLibel := '';
BOK.Visible := False;
BAnnul.Visible := False;
end; |
Partager