const
COL_YESNO = 0; // visible - checkbox - user can click to toggle
COL_TITLE = 1; // visible - constant
COL_SEQ = 2; // visible - user can change
COL_DESCRIPTION = 3; // visible - constant
COL_TABLECODE = 4; // remaing columns hidden...
COL_COLUMN = 5;
COL_ACCUM = 6;
COL_LENGTH = 7; // not actually used.
COL_TYPE = 8; // not actually used.
COL_SAVESELECT = 9;
COL_SAVESEQ = 10;
COL_FIRSTHIDDEN = COL_TABLECODE;
COL_LASTHIDDEN = COL_SAVESEQ;
{Toggle text in the indicated column of a string grid.}
procedure ToggleColumnText( Grid:TObject; ACol,ARow:integer;
Text1:string; Text2:string='' );
begin
with Grid as TStringGrid do
if ARow >= FixedRows then begin
if Cells[ACol, ARow] = Text1 then Cells[ACol,ARow] := Text2
else Cells[ACol,ARow] := Text1;
end; {if ARow}
end;
{Toggle L.H. column (check box) on any click in column zero.}
procedure TQSpecs.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
nCol,nRow:integer;
begin
(Sender as TStringGrid).MouseToCell(X,Y,nCol,nRow);
if nCol=COL_YESNO then ToggleColumnText( Sender, nCol, nRow, 'Yes' );
end;
{Toggle checkbox on space, allow [Esc] to un-do keying, else only 0-9 + Bs.}
procedure TQSpecs.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
nRow:integer;
begin
with Sender as TStringGrid do begin
nRow := Selection.Top;
if (Key = ' ') then
begin
ToggleColumnText( Sender, 0, nRow, 'Yes' );
Key := Chr(0);
EditorMode := False;
end {if space}
else
begin
if not (Key in ['0'..'9',#8,#13,#26,#27]) then Key := #0;
if Ord(Key) = 27 then Key := Chr(26);
end;
end; {with}
end;
{If user presses <Enter> while in grid, process as if pbOk clicked.}
procedure TQSpecs.StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then begin
StringGrid1.EditorMode := False;
pbOkClick( Sender );
end;
end;
{Override grid draw cell to use check box in col zero and center SEQ no.}
procedure TQSpecs.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
ARect: TRect; State: TGridDrawState);
{1 - Draw a check box in the specified rectangle.}
{1} procedure DrawCheckBox( ACanvas:TCanvas; ARect:TRect; YesOrNo:string );
{1} var
{1} bBitMap:TBitMap;
{1} PutHere:TRect;
{1} begin
{1} {Paint a checkbox 4 pixels over and 1 pixel down.}
{1} PutHere := Rect(ARect.Left+4,ARect.Top+1,ARect.Left+17,ARect.Top+14);
{1} if YesOrNo = 'Yes' then bBitMap := bmChecked else bBitMap := bmUnchecked;
{1} ACanvas.FillRect(ARect);
{1} ACanvas.CopyRect( PutHere, bBitMap.Canvas, Rect(0,0,12,12) );
{1} end;
begin
with Sender as TStringGrid do begin
if (ACol=COL_YESNO) and (ARow >= FixedRows) then
DrawCheckBox( Canvas, ARect, Cells[COL_YESNO,ARow] ); // First col.
if (ARow=000) then
CenterText(Canvas,ARect,Cells[ACol,0]); // All cols in heading.
if (ACol = COL_SEQ) then
CenterText(Canvas,ARect,Cells[ACol,ARow]); // All rows for Seq no.
end; {with}
end;
{On Form Create: Initialize grid and other variables}
procedure TQSpecs.FormCreate(Sender: TObject);
begin
:
:
bmChecked := TBitMap.Create;
bmUnchecked := TBitMap.Create;
ImageList1.GetBitmap(0,bmUnchecked);
ImageList1.GetBitmap(1,bmChecked);
:
:
end;