2

We have just upgraded from Delphi 2010 to XE4 and using FireMonkey for the first time, so stumbling about in the dark a bit trying to figure out how it all works.

As per a query a while back I'm trying to get individual cells in a TGrid component to display differently based on some rule. I have worked through the helpful code posted by Mike Sutton:

Firemonkey Grid Control - Styling a Cell based on a value (via the OnGetValue function call)

I had to make a few changes to get it to compile in XE4; it all looks ok when running the code, except that:

  1. FontFill is not recognized, so have blanked this out for now.
  2. The font style is not changing at all, it displays as the default style, no matter what.

The relevant code (the rest is pretty much as per the link above):

Procedure TFinancialCell.ApplyStyle;
var 
  T: TFMXObject;
begin
  inherited;
  ApplyStyling;
end;

Procedure TFinancialCell.ApplyStyling;
begin
//  If IsNegative then
//    FontFill.Color:=claRed
//  else
//    FontFill.Color:=claBlack;

  Font.Style:=[TFontStyle.fsItalic];

  If IsImportant then
    Font.Style:=[TFontStyle.fsBold]
  else
    Font.Style:=[];

  If Assigned(Font.OnChanged) then
    Font.OnChanged(Font);

  Repaint;
end;

The IsImportant flags are being set correctly so that doesn't seem to be the problem.

Any help with this would really be appreciated. Apologies in advance for anything stupid I might be missing.

Community
  • 1
  • 1
Alex
  • 543
  • 1
  • 9
  • 21
  • Excellent question, I'd like to know this myself. – Warren P May 10 '13 at 12:31
  • The only other potentially useful info I have found so far is here: http://monkeystyler.com/blog/entry/applystyle-and-freestyle-in-firemonkey However, I have no idea whether this is relevant to my query or not, as I don't understand the style code well enough. The original code mentioned in my query seems to work well with people that tried it when it was posted; I'm not sure whether it's an XE3/XE4 change that is causing it not to work. – Alex May 10 '13 at 14:37

1 Answers1

2

That article has largely been superseded by some stuff in my FireMonkey Guide site, http://monkeystyler.com/guide/Category:Grids

From XE3 onwards if you want to modify stuff you need to remove the appropriate item from the StyledSettings property,

StyledSettings := StyledSettings - [TStyledSetting.ssStyle, TStyledSetting.ssFontColor]

etc.

To change the font color use the FontColor property

Mike Sutton
  • 4,191
  • 4
  • 29
  • 42
  • Thanks Mike, I've got it working now, brilliant. I have to confess that it wasn't obvious to me where to put this code (I'm sure I'll get there in time!); after trial and error I dropped it into TFinancialCell.ApplyStyling and then it worked, so I presume this is correct? – Alex May 11 '13 at 15:26
  • If you're using a custom cell class pop it in the constructor as it only needs to be run once. See the example via the link I gave. – Mike Sutton May 11 '13 at 21:23