cancel
Showing results for 
Search instead for 
Did you mean: 

how to runtime change font for text object and/or Field object?

Former Member
0 Kudos

Hi

I need at runtime to change the font of text objects and/or Field objects. Any one can help me?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Moved to Legacy SDK support forum

0 Kudos

Hi,

If you have an IFontDispPtr dispatch pointer, things become easy. All you need to do is to call the font API to put new font in, like

myIFontPtr->put_Name("Times New Roman");

Hope this helps.

Congjin

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi All,

Thanks for all your help.

I have got a solution here:

var MyFont: TFont;

crField : IFieldObject;

sec : TCRSection;

j : integer;

begin

sec := (Sender as TCRSection);

for j := 1 to sec.ReportObjects.Count do

begin

Sec.ReportObjects.Item[j].QueryInterface(IID_IFieldObject,crField);

if crField <> nil then

begin

MyFont.Size := StrToInt(Edit3.Text);

MyFont.Name :=Edit2.Text;

GetOleFont(MyFont, OleFont);

crField.Font := OleFont;

end;

end;

Former Member
0 Kudos

I know parameter is a way. But I did not try it. I will try to see if I could runtime create parameters and text boxes and associate the text boxes to the parameters.

But I think the best way is still assign the font from the codes.

Former Member
0 Kudos

Hi

Thanks for the answaer. I did not ask my question clearly. The way you suggested is the way I am using now. What I really want is that I need control the font from my application codes through crystal report activeX. I am using delphi, I want to control this from my delphi code. I runtime create the text object, I can assign the text color, ie. textcontrol.textcolor := clRed; I want something like, Textcontrol.font.name := 'Arial'; but I can't. Because the font is type of IFontDispatch. I don't how to do it or maybe theere is no way to achieve it?

Former Member
0 Kudos

I'm not familiar enough with the ActiveX controls to know if it's possible, but you could always add a parameter, say {?Font}, to the report, and use that in the Font Formula field instead of the code suggested above... (I know you can set parameters with the ActiveX controls...)

HTH,

Carl

Former Member
0 Kudos

Right click on the particular field --> Select Format Field --> Navigate to Font Menu --> Click on the formula button displayed as *x+2" next to Font --> Opens Formula Editor. Write the condition here


if ({db.value} = 'abc') then // If db value matches abc then change the font to Times New Roman else Arial
    'Times New Roman'
else
    'Arial'