Hopefully, replying-to an old support request will bring it back to life. (i.e., I hope you can see this.)
I am still having issues with column indexing issues in the OnGetCellColor event for TAdvDbGrid (or TAdvStringGrid) when that event is being used for PDF output. I've observed this on two computers. To help convey the issue, I wrote a test unit that you can use. I hope it can be duplicated at your end.
Below are two files for the testPdfColorsUnit: a PAS file and a text-version of the DFM file.
Note: The generated PDF and HTML files are put into the computer's temp folder, as shown in function tempFile() below.
PAS code:
unit testPdfColorsUnit;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.Grids, AdvObj, BaseGrid,
AdvGrid, Vcl.StdCtrls, AdvCustomComponent, AdvPDFIO, AdvGridPDFIO, HTMLText;
type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
AdvGridPDFIO1: TAdvGridPDFIO;
cbIndex: TCheckBox;
cbColor: TCheckBox;
cbName: TCheckBox;
cbOrig: TCheckBox;
cbCurrent: TCheckBox;
cbDiff: TCheckBox;
pdfBtn: TButton;
htmlBtn: TButton;
HTMLStaticText1: THTMLStaticText;
procedure FormCreate(Sender: TObject);
procedure AdvStringGrid1GetCellColor(Sender: TObject; ARow, ACol: Integer;
AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
procedure onPdfClick(Sender: TObject);
procedure onClickToggleCol(Sender: TObject);
procedure onHtmlClick(Sender: TObject);
private
function cbStates : string;
function tempFile( const basename:string ) : string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ShellApi;
{$R *.dfm}
const COLTITLE_INDEX = 'index';
COLTITLE_COLOR = 'color';
COLTITLE_PLAYER = 'name';
COLTITLE_TEAM = 'team';
COLTITLE_ORIG = 'orig';
COLTITLE_CURR = 'curr';
COLTITLE_CHANGE = 'diff';
procedure TForm1.FormCreate(Sender: TObject);
const DUMMY_DATA : Array of String = [
'' + COLTITLE_INDEX + ','
+ COLTITLE_COLOR + ','
+ COLTITLE_PLAYER + ','
+ COLTITLE_TEAM + ','
+ COLTITLE_ORIG + ','
+ COLTITLE_CURR + ','
+ COLTITLE_CHANGE + '',
'3,13299711,"Joshua",Team-Z,5.3,5.3,0',
'65,14730722,"Fred",Team-P,7.3,7.0,-0.3',
'87,12185009,"Ted",Team-W,5.3,5.4,0.1',
'1,16704726,"Chris",Team-B,6.9,7,0.1',
'69,11651309,"Steve",Team-Q,5.2,5.4,0.2',
'8,15395583,"Conrado",Team-S,8.4,8.3,-0.1',
'33,14155762,"William",Team-L,3.9,4,0.1'
];
var sList : TStringList;
csvFile, s : string;
begin
// Populate grid.
sList := TStringList.Create;
for s in DUMMY_DATA do sList.Add(s);
csvFile := tempFile( 'sampleDataForPdfColorTesting.csv' );
try
sList.SaveToFile( csvFile );
AdvStringGrid1.LoadFromCSV( csvFile );
finally
DeleteFile( csvFile );
sList.Free;
end;
// Syncronize checkbox captions to column headers.
cbIndex.Caption := COLTITLE_INDEX;
cbColor.Caption := COLTITLE_COLOR;
cbName.Caption := COLTITLE_PLAYER;
cbOrig.Caption := COLTITLE_ORIG;
cbCurrent.Caption := COLTITLE_CURR;
cbDiff.Caption := COLTITLE_CHANGE;
end;
function TForm1.cbStates : string;
function cbState( const cb : TCheckbox ) : string;
begin
Result := cb.Caption + '[';
if cb.Checked then Result := Result + 'X' else Result := Result + ' ';
Result := Result + '] ';
end;
begin
Result := cbState(cbIndex)+cbState(cbColor)+cbState(cbName)+cbState(cbOrig)+cbState(cbCurrent)+cbState(cbDiff);
end;
function TForm1.tempFile( const basename:string ) : string;
var tempFolder: array[0..MAX_PATH] of Char;
begin
GetTempPath(MAX_PATH, @tempFolder); // trailing backslash is included here.
Result := StrPas(tempFolder) + basename;
end;
procedure TForm1.onClickToggleCol(Sender: TObject);
var col : integer;
begin
col := AdvStringGrid1.ColumnByHeader( (Sender as TCheckbox).Caption );
if (Sender as TCheckbox).Checked
then AdvStringGrid1.UnHideColumn( col )
else AdvStringGrid1.HideColumn( col );
end;
procedure TForm1.AdvStringGrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var colTitle, valStr : string;
rankDiff : single;
teamColorColIndex : integer;
teamColorStr : string;
teamColorInt : integer;
begin
if ARow=0 then
begin
AFont.Style := [fsBold];
Exit;
end;
colTitle := AdvStringGrid1.Cells[ ACol, 0 ];
if colTitle=COLTITLE_PLAYER then
begin
AFont.Style := [fsBold];
end
else if colTitle=COLTITLE_TEAM then
begin
AFont.Style := [fsBold];
teamColorColIndex := AdvStringGrid1.ColumnByHeader( COLTITLE_COLOR );
teamColorStr := AdvStringGrid1.Cells[teamColorColIndex, ARow];
teamColorInt := StrToInt( teamColorStr );
ABrush.Color := TColor( teamColorInt );
end
else if colTitle=COLTITLE_ORIG then
begin
AFont.Style := [fsItalic];
end
else if colTitle=COLTITLE_CHANGE then
begin
valStr := AdvStringGrid1.Cells[ ACol, ARow ];
rankDiff := StrToFloatDef( valStr, 0 );
if rankDiff<0 then AFont.Color := clRed
else if rankDiff>0 then AFont.Color := clGreen
else AFont.Color := clGray;
end;
end;
procedure TForm1.onPdfClick(Sender: TObject);
var tempPdfFile : string;
begin
tempPdfFile := tempFile( 'sampleColorTestOutput.pdf' );
AdvGridPDFIO1.Grid := AdvStringGrid1;
AdvGridPDFIO1.Options.Header := cbStates;
AdvGridPDFIO1.Options.OpenInPDFReader := TRUE;
AdvGridPDFIO1.Save( tempPdfFile );
end;
procedure TForm1.onHtmlClick(Sender: TObject);
var tempPdfFile : string;
begin
tempPdfFile := tempFile( 'sampleColorTestOutput.html' );
AdvStringGrid1.SaveToHtml( tempPdfFile );
ShellExecute(Handle, nil, PChar(tempPdfFile), nil, nil, SW_SHOWNORMAL);
end;
end.
DFM code:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 431
ClientWidth = 814
Color = clBtnFace
Constraints.MinHeight = 300
Constraints.MinWidth = 830
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
DesignSize = (
814
431)
PixelsPerInch = 96
TextHeight = 13
object AdvStringGrid1: TAdvStringGrid
Left = 8
Top = 8
Width = 798
Height = 153
Anchors = [akLeft, akTop, akRight, akBottom]
DrawingStyle = gdsClassic
FixedColor = clWhite
TabOrder = 0
GridLineColor = 13948116
GridFixedLineColor = 11250603
OnGetCellColor = AdvStringGrid1GetCellColor
ActiveCellFont.Charset = DEFAULT_CHARSET
ActiveCellFont.Color = 4474440
ActiveCellFont.Height = -11
ActiveCellFont.Name = 'Tahoma'
ActiveCellFont.Style = [fsBold]
ActiveCellColor = 11565130
ActiveCellColorTo = 11565130
BorderColor = 11250603
ColumnSize.Stretch = True
ColumnSize.StretchAll = True
ControlLook.FixedGradientFrom = clWhite
ControlLook.FixedGradientTo = clWhite
ControlLook.FixedGradientHoverFrom = clGray
ControlLook.FixedGradientHoverTo = clWhite
ControlLook.FixedGradientHoverMirrorFrom = clWhite
ControlLook.FixedGradientHoverMirrorTo = clWhite
ControlLook.FixedGradientHoverBorder = 11645361
ControlLook.FixedGradientDownFrom = clWhite
ControlLook.FixedGradientDownTo = clWhite
ControlLook.FixedGradientDownMirrorFrom = clWhite
ControlLook.FixedGradientDownMirrorTo = clWhite
ControlLook.FixedGradientDownBorder = 11250603
ControlLook.DropDownHeader.Font.Charset = DEFAULT_CHARSET
ControlLook.DropDownHeader.Font.Color = clWindowText
ControlLook.DropDownHeader.Font.Height = -11
ControlLook.DropDownHeader.Font.Name = 'Tahoma'
ControlLook.DropDownHeader.Font.Style = []
ControlLook.DropDownHeader.Visible = True
ControlLook.DropDownHeader.Buttons = <>
ControlLook.DropDownFooter.Font.Charset = DEFAULT_CHARSET
ControlLook.DropDownFooter.Font.Color = clWindowText
ControlLook.DropDownFooter.Font.Height = -11
ControlLook.DropDownFooter.Font.Name = 'Tahoma'
ControlLook.DropDownFooter.Font.Style = []
ControlLook.DropDownFooter.Visible = True
ControlLook.DropDownFooter.Buttons = <>
Filter = <>
FilterDropDown.Font.Charset = DEFAULT_CHARSET
FilterDropDown.Font.Color = clWindowText
FilterDropDown.Font.Height = -11
FilterDropDown.Font.Name = 'Tahoma'
FilterDropDown.Font.Style = []
FilterDropDown.TextChecked = 'Checked'
FilterDropDown.TextUnChecked = 'Unchecked'
FilterDropDownClear = '(All)'
FilterEdit.TypeNames.Strings = (
'Starts with'
'Ends with'
'Contains'
'Not contains'
'Equal'
'Not equal'
'Larger than'
'Smaller than'
'Clear')
FixedRowHeight = 22
FixedFont.Charset = DEFAULT_CHARSET
FixedFont.Color = 3881787
FixedFont.Height = -11
FixedFont.Name = 'Tahoma'
FixedFont.Style = [fsBold]
FloatFormat = '%.2f'
HoverButtons.Buttons = <>
HTMLSettings.ImageFolder = 'images'
HTMLSettings.ImageBaseName = 'img'
Look = glCustom
PrintSettings.DateFormat = 'dd/mm/yyyy'
PrintSettings.Font.Charset = DEFAULT_CHARSET
PrintSettings.Font.Color = clWindowText
PrintSettings.Font.Height = -11
PrintSettings.Font.Name = 'Tahoma'
PrintSettings.Font.Style = []
PrintSettings.FixedFont.Charset = DEFAULT_CHARSET
PrintSettings.FixedFont.Color = clWindowText
PrintSettings.FixedFont.Height = -11
PrintSettings.FixedFont.Name = 'Tahoma'
PrintSettings.FixedFont.Style = []
PrintSettings.HeaderFont.Charset = DEFAULT_CHARSET
PrintSettings.HeaderFont.Color = clWindowText
PrintSettings.HeaderFont.Height = -11
PrintSettings.HeaderFont.Name = 'Tahoma'
PrintSettings.HeaderFont.Style = []
PrintSettings.FooterFont.Charset = DEFAULT_CHARSET
PrintSettings.FooterFont.Color = clWindowText
PrintSettings.FooterFont.Height = -11
PrintSettings.FooterFont.Name = 'Tahoma'
PrintSettings.FooterFont.Style = []
PrintSettings.PageNumSep = '/'
SearchFooter.ColorTo = clNone
SearchFooter.FindNextCaption = 'Find &next'
SearchFooter.FindPrevCaption = 'Find &previous'
SearchFooter.Font.Charset = DEFAULT_CHARSET
SearchFooter.Font.Color = clWindowText
SearchFooter.Font.Height = -11
SearchFooter.Font.Name = 'Tahoma'
SearchFooter.Font.Style = []
SearchFooter.HighLightCaption = 'Highlight'
SearchFooter.HintClose = 'Close'
SearchFooter.HintFindNext = 'Find next occurrence'
SearchFooter.HintFindPrev = 'Find previous occurrence'
SearchFooter.HintHighlight = 'Highlight occurrences'
SearchFooter.MatchCaseCaption = 'Match case'
SearchFooter.ResultFormat = '(%d of %d)'
SelectionColor = 13744549
ShowDesignHelper = False
SortSettings.HeaderColor = clWhite
SortSettings.HeaderColorTo = clWhite
SortSettings.HeaderMirrorColor = clWhite
SortSettings.HeaderMirrorColorTo = clWhite
Version = '8.7.2.6'
ColWidths = (
64
179
178
178
178)
RowHeights = (
22
22
22
22
22
22
22
22
22
22)
object AdvGridPDFIO1: TAdvGridPDFIO
Left = 784
Top = 344
Width = 26
Height = 26
Visible = True
Grid = AdvStringGrid1
Options.DefaultFont.Name = 'Arial'
Options.Header = 'TMS PDF Header'
Options.Footer = 'TMS PDF Footer'
Options.Margins.Left = 20.000000000000000000
Options.Margins.Top = 50.000000000000000000
Options.Margins.Right = 20.000000000000000000
Options.Margins.Bottom = 50.000000000000000000
Options.HeaderFont.Name = 'Arial'
Options.FooterFont.Name = 'Arial'
Options.HeaderMargins.Left = 5.000000000000000000
Options.HeaderMargins.Top = 5.000000000000000000
Options.HeaderMargins.Right = 5.000000000000000000
Options.HeaderMargins.Bottom = 5.000000000000000000
Options.FooterMargins.Left = 5.000000000000000000
Options.FooterMargins.Top = 5.000000000000000000
Options.FooterMargins.Right = 5.000000000000000000
Options.FooterMargins.Bottom = 5.000000000000000000
Options.PageNumberMargins.Left = 10.000000000000000000
Options.PageNumberMargins.Top = 5.000000000000000000
Options.PageNumberMargins.Right = 10.000000000000000000
Options.PageNumberMargins.Bottom = 5.000000000000000000
Options.PageNumberFormat = '%d'
Options.PageNumberFont.Name = 'Arial'
end
end
object pdfBtn: TButton
Left = 598
Top = 400
Width = 97
Height = 25
Anchors = [akRight, akBottom]
Caption = 'PDF'
TabOrder = 1
OnClick = onPdfClick
end
object cbIndex: TCheckBox
Left = 25
Top = 404
Width = 57
Height = 17
Anchors = [akLeft, akBottom]
Caption = 'cbIndex'
Checked = True
State = cbChecked
TabOrder = 2
OnClick = onClickToggleCol
end
object cbColor: TCheckBox
Left = 125
Top = 404
Width = 57
Height = 17
Anchors = [akLeft, akBottom]
Caption = 'cbColor'
Checked = True
State = cbChecked
TabOrder = 3
OnClick = onClickToggleCol
end
object cbName: TCheckBox
Left = 225
Top = 404
Width = 57
Height = 17
Anchors = [akLeft, akBottom]
Caption = 'cbName'
Checked = True
State = cbChecked
TabOrder = 4
OnClick = onClickToggleCol
end
object cbOrig: TCheckBox
Left = 325
Top = 404
Width = 57
Height = 17
Anchors = [akLeft, akBottom]
Caption = 'cbOrig'
Checked = True
State = cbChecked
TabOrder = 5
OnClick = onClickToggleCol
end
object cbCurrent: TCheckBox
Left = 425
Top = 404
Width = 68
Height = 17
Anchors = [akLeft, akBottom]
Caption = 'cbCurrent'
Checked = True
State = cbChecked
TabOrder = 6
OnClick = onClickToggleCol
end
object cbDiff: TCheckBox
Left = 525
Top = 404
Width = 44
Height = 17
Anchors = [akLeft, akBottom]
Caption = 'cbDiff'
Checked = True
State = cbChecked
TabOrder = 7
OnClick = onClickToggleCol
end
object htmlBtn: TButton
Left = 710
Top = 400
Width = 96
Height = 25
Anchors = [akRight, akBottom]
Caption = 'HTML'
TabOrder = 8
OnClick = onHtmlClick
end
object HTMLStaticText1: THTMLStaticText
Left = 8
Top = 167
Width = 798
Height = 227
Anchors = [akLeft, akRight, akBottom]
HTMLText.Strings = (
'<FONT size="10">Remove random columns by unchecking any combinat' +
'ion of checkboxes below. The HTML output always renders the col' +
'umns properly, but the '
'<B><FONT color="#FF0000">PDF output is unreliable</FONT></B>. O' +
'bserve how the colors meant for specific columns are sometimes c' +
'orrupted in the PDF '
'output.<br><br>'
'<FONT color="#800000" bgcolor="#FFFF80">If my column indexing in' +
' the <B>OnGetCellColor </B>event is incorrect, then I don'#39't know' +
' why it works successfully on the '
'screen and '
'HTML, but not in the PDF when <U>certain columns</U> are hidden ' +
'from the grid.</FONT>'
'</FONT>'
'<br><br>'
'<u>One example</u>:<br><br>'
'<OL><LI>Toggle off the <B>color</B> column.</LI>'
'<LI>Click the PDF button to see the output.</LI>'
'<LI>When I test it,<FONT color="#804040"> cells in the <B>name</' +
'B> column are colored instead of in the <b>team</b> column, and ' +
' the coloring for the <b>diff</b> '
'column is repeated in the <b>curr</b> collumn</FONT>.</LI>'
'<LI>Now click the HTML button, and observe how <FONT color="#008' +
'000">everything is always as expected</FONT></LI>'
'</OL><br><br>'
'<FONT color="#000080" ><I>Experiment with toggling other columns' +
'. Some combinations render fine in the PDF, while other combina' +
'tions produced different '
'results.</I></FONT>')
TabOrder = 9
Version = '1.6.0.0'
end
end