fonts - Applying a style to a Delphi XE4 Firemonkey StringGrid cell at runtime -


i trying apply style xe4 fm stringgrid @ runtime, unable find correct syntax this.

the stringgrid inherits 'textcellstyle' (the default) have created @ design time, , display cells in stringgrid according style.

what ideally change colour of fonts in specific cells (negative=red, positive=green etc) @ runtime, cannot work out how this, unable access stylelookup @ cell level.

please remember query relates tstringgrid, , not tgrid, our application requires allocate memory grid dynamically @ run-time, , easier stringgrid.

any appreciated, , in advance.

i have been attempting learn how tgrid, , mike sutton's have managed this.

[see changing ttextcell background colour @ runtime xe4 background.]

having managed right, attempted similar logic on tstringgrid , worked fine. stringgrid doesn't use grid1getvalue, hard-coded random numbers grid in formcreate.

[in code below have style called textcellstyle; 'background' component of textcellstyle added trectangle, call on 'fill' property of trectangle. still not on top of styles yet, see link above.]

my code, in case it's helpful:

    procedure tform1.formcreate(sender : tobject);      begin       { create column }       stringgrid1.addobject(tfinancialcolumn.createstringgrid1));         { hard-code rows }       stringgrid1.cells[0,0] :='0';       stringgrid1.cells[0,1] :='1';       stringgrid1.cells[0,2] :='2';       stringgrid1.cells[0,3] :='3';       stringgrid1.cells[0,4] :='4';       stringgrid1.cells[0,5] :='5';       stringgrid1.cells[0,6] :='6';       stringgrid1.cells[0,7] :='7';       stringgrid1.cells[0,8] :='8';       stringgrid1.cells[0,9] :='9';       stringgrid1.cells[0,10]:='10';       { hard-code bunch of numbers. note hash in front of number  flag isimportant }       stringgrid1.cells[1,0] :='-10';       stringgrid1.cells[1,1] :='-6.86999999';       stringgrid1.cells[1,2] :='76.0999999';       stringgrid1.cells[1,3] :='#10.25';               stringgrid1.cells[1,4] :='#17.2900006';       stringgrid1.cells[1,5] :='#57.1599993';       stringgrid1.cells[1,6] :='21.86000';       stringgrid1.cells[1,7] :='6.17';       stringgrid1.cells[1,8] :='27.219999';       stringgrid1.cells[1,9] :='#32.56000';       stringgrid1.cells[1,10]:='-1.7999';     end;       function tfinancialcolumn.createcellcontrol : tstyledcontrol;      begin       result:=tfinancialcell.create(self);        ttextcell(result).ontyping:=dotextchanged;       ttextcell(result).onexit  :=dotextexit;     end;      constructor tfinancialcell.create(aowner : tcomponent);      begin       inherited;       stylelookup:='textcellstyle';       styledsettings:=styledsettings-[tstyledsetting.ssstyle,tstyledsetting.ssfontcolor]; { line must here apply new style; clears 'default' style settings }       textalign:=ttextalign.tatrailing;     end;      procedure tfinancialcell.setdata(const value          : tvalue);      var        f                                                   : single;       o                                                   : tfmxobject;       s                                                   : string;      begin       s:=value.asstring;        if length(s)>1        begin          fisimportant:=s[1]='#';         if isimportant           s:=copy(value.asstring,2,maxint)         else           s:=value.asstring;          f:=strtofloat(s);         inherited setdata(format('%n',[f]));         fisnegative:=f<0;          applystyling;       end;       end;      procedure tfinancialcell.applystyle;      var        t                                                   : tfmxobject;      begin       inherited;        t:=findstyleresource('rectangle1');        if t trectangle       begin          if isnegative          begin           trectangle(t).fill.color:=clared;          end;         end;        applystyling;     end;      procedure tfinancialcell.applystyling;      var        t                                                   : tfmxobject;      begin       if isnegative         fontcolor:=clablack       else         fontcolor:=clagreen;        if isimportant font.style:=[tfontstyle.fsitalic,tfontstyle.fsbold]; { repeat italic else bold, ie overwrites italic bold }        if assigned(font.onchanged)         font.onchanged(font);        repaint;     end; 

this code works in terms of restyling fonts , backgrounds. suggestions improve above welcome, can help.

the styling falls apart start scrolling, though, haven't figured out how fix yet. suggestion welcome!


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -