Create TppFont or TFont in RAP
Hello,
how is it possible to create a TFont or TppFontObject in RAP. If call the
statement "Font:=TFont.Create;" all seems going well, but if i set a
property like the "Font.Name:='Arial' " then i get an exception on
runtime.
any ideas (RB 10.05)
--
best regards
chris (EULANDA)
www.eulanda.com
ERP SOLUTIONS
how is it possible to create a TFont or TppFontObject in RAP. If call the
statement "Font:=TFont.Create;" all seems going well, but if i set a
property like the "Font.Name:='Arial' " then i get an exception on
runtime.
any ideas (RB 10.05)
--
best regards
chris (EULANDA)
www.eulanda.com
ERP SOLUTIONS
This discussion has been closed.
Comments
support the constructor. We can add this for the next maintenance release.
For now, modify ppRTTI.pas to include the following work around:
- add an implementation section 'uses' that includes the Graphics unit
- modify TraTObjectRTTI.CallMethod to look like this...
if CompareText(aMethodName, 'Create') = 0 then
begin
lClass := aParams[0].ClassType;
if (lClass.ClassName = 'TFont') then
lObject := TFont.Create
else
lObject := lClass.Create;
aParams.SetParamValue(1, Integer(lObject));
end
- modify the implentation section only, leave the interface section
unchanged
In debugging I notice that TObject.Create is called rather than
TFont.Create, thus the object is not valid. As you can see from the above
code, RAP uses a class reference to instantiate a new object. Evidently
Delphi cannot determine that TFont.Create should be called rather than
TObject.Create.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
the exception is gone, but the Font seems to be NIL. I pass it as a
parameter in a PassThrough and it seems it do nothing. If i pass instead a
label1.Font from an existing label, and it works.
sample:
var
Font : TFont;
begin
Font:=TFont.Create;
Font.Name:='Times New Roman';
Richtext1.Richtext:=HtmlToRtf('bla bla',Font);
ShowMessage(Font.Name);
Font.Free;
end;
my PassThrough is HtmlToRtf, if i comment this line out, it shows the
fontname in Show Message. If the line is executed then the message is empty.
The Font seems to be cleared in the pass through. But the same pass through
works if i pass the label.font from an existing label.
My PassThrough:
class function TmyHtmlToRtfFunction.GetSignature: String;
begin
Result := 'function HtmlToRtf(const Html : String; Font: TFont):String;';
end;
procedure TmyHtmlToRtfFunction.ExecuteFunction(aParams: TraParamList);
var
lsHtml : String;
lsFont : TFont;
lsResult : String;
lRichEdit : TRichEdit;
lFontCreated : Boolean;
begin
lsHtml:='';
lsFont:=Nil;
lsResult:='';
lRichEdit:=Nil;
lFontCreated:=false;
try
GetParamValue(0,lsHtml);
GetParamValue(1,lsFont);
if lsFont=Nil then
begin
lsFont:=TFont.Create;
lsFont.Name:='Arial';
lsFont.Size:=10;
lsFont.Color:=clBlack;
lFontCreated:=True;
end;
lRichEdit := TRichEdit.Create(nil);
lRichEdit.Parent := emStartUpForm;
lRichEdit.Font.Assign(lsFont);
HTMLtoRTF(lsHtml, lRichEdit);
lsResult:=GetRtf(lRichEdit);
finally
SetParamValue(2, lsResult);
lRichEdit.Free;
if lFontCreated then lsFont.Free;
end;
end;
The idea of the font is, to pass a default fopnt to my conversion routine.
Because the IDE seems not to allow a TppRichtext.Font a sa default, so my
idea was to create one in RAP.
any idea?
--
best regards
chris (EULANDA)
www.eulanda.com
ERP SOLUTIONS