Posted this in LCL as this might be a more generic problem...
I've modified a dbgrid to show the text of memo lines (normally it just shows (Memo); thanks to User137.
I use DefaultDrawing:=false and a OnDrawColumnCell handler (see code below).
This works as it draws the cells.
However, when I show e.g. a message box, I suppose the drawing code does not take into account that it should not draw over the messagebox which is in the foreground... See screenshot.
Additionally, when moving the showmessage dialog, I get the unique opportunity to use it as some kind of pencil eraser on the grid... (hard to say in words, but I'm sure the effect will be well-known to the seasoned GUI guys)
That's strange, because I'm basically just reusing the code already in the LCL.... obviously though I forgot something....
How can I fix this?
Thanks!
procedure TForm1.ResultsGridDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
// Draw memo text instead of (Memo)
// Note: grid DefaultDrawing property must be off to avoid duplicate drawing
// To get this, I basically copied the existing DefaultDrawColumnCell procedure
// but tested for memo first. If no memo, pass on to default procedure.
// Maybe slower, more complicated, but it allows for changes in the
// core Lazarus DefaultDrawColumnCell procedure.
// Thanks to User137 on the forum
var
OverrideDraw: boolean; //determine if we're going to override normal Lazarus draw routines
OurDisplayString: string;
CurrentField: TField;
DataRow: Integer;
begin
OverrideDraw:=false;
try
CurrentField := Column.Field;
if CurrentField.DataType = ftMemo then
begin
OverRideDraw:=true;
end;
except
on E: exception do
begin
// We might have an inactive datalink or whatever,
// in that case, pass on our problems to the existing
// procedure.
//showMessage('Exception: ' + E.Classname + '/' + E.Message);
OverRideDraw:=false;
end;
end;
if OverRideDraw=false then
begin
// Call normal procedure to handle drawing for us.
ResultsGrid.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
else
begin
// Get to work displaying our memo contents
// Basically shamelessly ripped from
// DefaultDrawColumnCell
// maybe fix something for first/header row
if CurrentField<>nil then
begin
//DO display memo ;) OurDisplayString is string to be displayed
OurDisplayString := CurrentField.AsString; //DisplayText will only show (Memo)
end
else
begin
OurDisplayString := '';
end;
//Actual drawing, taken from Grids.DrawCellText coding:
ResultsGrid.Canvas.TextRect(Rect,Rect.Left,Rect.Top, OurDisplayString);
end;
end;