RB 7.04 D6 RAP
How in RAP do I select text in a Rich Text control and apply
formatting attributes? Is there RTTI support for this? If not have
you a demo that provides an example of adding it as custom RTTI or
passthroughs?
Thanks,
Rick Matthews
Dartek Systems Inc.
Comments
In order to change the format of the text inside a TppRichText component,
you will need to use the SelText and SelAttributes properties. These
properties are available in RAP. See the help on TppRichText for more
information on how the SelAttributes works.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
demo project or some sample rap code that
1) Finds a text string and bolds it
2) Finds a text string and replaces it with a new string?
Many thanks,
I apoligize, I was not completely correct. Since the SelAttributes.Style
property is a Set, it is not natively supported in RAP. You will need to
either create a pass-thru function to access this set or add the specific
set capability by creating a new TraRTTI descendent, as described below.
--------------------------------------------------
Article: Providing Support for Set Types
---------------------------------------------------
This code demonstrates how you can use your TraRTTI descendants
to provide support for Set type properties without using Sets.
Version 1.0 of RAP does not support Set types. However, it is
possible, using RTTI, to supply support for Set type properties.
Take, for instance, TFont's Style property which is of type
TFontStyles - a set. In order to support this property via RAP,
we have added some boolean properties to TFont in the TraTFontRTTI
class, a TraRTTI descendant. Since TFontStyles is a set of fsBold,
fsItalic, fsUnderline and fsStrikeout, we have added Bold, Italic,
Underline and Strikeout to TFont. In this manner, you can set the
boolean properties in RAP and the TraFontRTTI class handles
transferring these values to and from the Style property in
Delphi's TFont. The following code demonstrates this.
Note: If you are unfamiliar with registering classes with RAP
via TraRTTI descendants, you should aquaint yourself with the
process by completing the Extending the RAP RTTI tutorial in the
RAP help file.
First we declare a new TraRTTI descendant, TraTFontRTTI,
to provide the new properties.
In GetPropList and GetPropRec, we add the new properties.
In GetPropValue, we transfer values from Delphi's TFont.Style
property to the boolean properties:
class function TraTFontRTTI.GetPropValue(aObject: TObject; const
aPropName: String; var aValue): Boolean;
begin
...
else if ppEqual(aPropName, 'Italic') then
{if fsItalic is in Style then set TFont.Italic to True}
Boolean(aValue) := (fsItalic in TFont(aObject).Style)
...
end;
In TraTFontRTTI.SetPropValue, we transfer values from our new
properties to Delphi's TFont.Style property:
class function TraTFontRTTI.SetPropValue(aObject: TObject; const
aPropName: String; var aValue): Boolean;
var
lFontStyles: TFontStyles;
begin
...
lFontStyles := TFont(aObject).Style;
...
else if ppEqual(aPropName, 'Italic') then
begin
{if TFont.Italic then add fsItalic to Style...}
if (Boolean(aValue)) then
include(lFontStyles, fsItalic)
else
exclude(lFontStyles, fsItalic);
TFont(aObject).Style := lFontStyles;
end
...
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks that almost did it for me. I have added RTTI for bold, italic,
color, size etc. and with a RichText component it works great on the
OnPrint event.
However I am getting odd results with a dbRichText. I either get no
formatting change or else it is applied to the entire object.
If I use a standard RichText and first assign the .RichText property
the value from the pipeline everything works fine.
Is there a timing issue or something else I have to be aware of?
Thanks,
Which event are you using to alter the SelAttributes? If you would like,
you can send a small example demonstrating what you are doing to
support@digital-metaphors.com in .zip format and I'll take a look at it for
you.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com