17 Jul 12 5:54
Many years ago (when Delphi 4 was new), we wrote a meeting room booking app, that allowed the reception people to load details of 6 room bookings into a paradox table, which assigned a booking code, room, start time and duration, and also type of booking (external customer, director, team etc).
The details are shown on a string grid set up with days across top, and time down left (each cell being 15 mins). Each cell displays the code of the meeting (calculated from the start time and meeting length) - this still works correctly.
Now, after 13 years, they want the cells coloured to represent the type of meeting!
I haven't touched Delphi in 9 years, and string grids since that was written in 1999!
However I can't get colouring to work :(
All I have done is to add some new TColor (for the colour), and integer (for the cell x and y co-ordinates) variables.
The grid now displays as before, except that the last cell entry, calculated for the last entry in the data table is displayed as a black cell (colour and font both black).
I have written the DrawCell procedure as below:
procedure TForm1.Grid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
TempBack, TempFont : TColor;
TempBack := Canvas.Brush.Color; //Save the current background colour
TempFont := Canvas.font.Color; // Save the current font colour
if (ACol = SelectedCol) and (ARow = SelectedRow) then // The cell is the one we want to change
with TStringGrid(Sender) do
TempBack := bkCol; // Set to required background colour
TempFont := TextCol; // Set to required font colour
Canvas.Brush.Color := TempBack;
Canvas.font.Color := TempFont;
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol, ARow]); //Rewrite the text
The calling code has been amended by adding the colour setting code:
// SetColours for meeting type
if gType = 'GG' then bkCol := clBlue
else if gType = 'PS' then bkCol:= clAqua
else if gType = 'MT' then bkCol:= clGreen
else if gType = 'SQ' then bkCol:= clMaroon
else if gType = 'SA' then bkCol:= clYellow;
txtCol := clBlack;
// make text visible on blue background
If Gtype ='GG' then txtCol := clWhite;
// the following code still works ok
for l := i to (i+j)-1 do
selectedCol := k;
selectedRow := l;
Grid1.cells[k,l] := sCode; // Add booking code to cell
Can anyone point me in the right direction?