I think the last "Handled" is wrong. This parameter tells the grid whether it should continue painting the specified cell. Since you provided an OnDrawCellText handler for the merged cells "Handled" should be true for these, but for the other cells "Handled" should be false. Therefore, there must be an "else" before the "Handled := false.
procedure TfrmMain.DrawCellTextHandler(Sender: TObject; ACol, ARow: Integer;
ARect: TRect; AState: TGridDrawState; AText: String; var Handled: Boolean);
var
ts: TTextStyle;
x, y: Integer;
bmp: TBitmap;
begin
Handled := True;
if (ACol in [1..2]) and (ARow = 0) then
begin
// Centered text
// ...
end else if (ACol in [3..4]) and (ARow = 0) then begin
// Centered text
// ...
end
else // <----------- ADDED
Handled := False;
end;
See also attached demo which is simpler than the example in the Lazarus folder.