WPCubed Product Support

Ho to get/set paragraph color?

Hello,

for a status display and an external toolbar (no WPTools-Toolbar) i need to get and set the color of the current paragraph (or the paragraph color of the selected text if ans is selected)

I have tried it with CurrAttr.ParColor and CurrAtr.GetColorEx with no success. The help says that GetColorEx can be used with WPAT_ParColor but i can not find WPAT_ParColor anywhere.

I als also tried:

WPRichText.ActivePar.ASetColor(WPAT_BGColor, aColor); and
WPRichText.SelectedTextAttr.ASetColor(WPAT_BGColor, aColor);

both with no success. What goes wrong with my code? (The set methods were followed by a ReformatAll)

Can cou give me a short hint?

Thanks in advance,
Ralf

#1 ♥ 0
6.7k Views 2 users read 3 min
support

What value do you use for 'aColor' ? That is not a TColor value, you need to combert it to an index value using CurrAttr.AddColor (as it was in V4).

Julian

#2 ♥ 0

@wpsupport:
What value do you use for 'aColor' ? That is not a TColor value, you need to combert it to an index value using CurrAttr.AddColor (as it was in V4).

Julian

Hi Julian,

according to the helpfile this value is a TColor:

Form the helpfile:
procedure ASetColor(WPAT_Code: Byte; Value: TColor);

So i had assigned a TColor value (clRed for example).

I will try to assign a color index this evening.

BTW: Is there a complete list of all WPAT_ codes somewhere, i havn't fond one yet.

Thanky,
Ralf

#3 ♥ 0
support

ASetColor indded expects a TColor, internalöly it does the conversion. But the CurrArr ParColor does not.

See the list here:

Maybe you should also set

WPAT_ShadingValue, 100

The easiest is to use CurrAttr since it changes sxome pros at once:

function TWPSetModeControl.GetParColor: Integer;
var a : Integer;
begin
Result := AGetDefault(WPAT_FGColor, 0);
if (AGet(WPAT_ShadingValue, a) and (a=0)) or
(AGet(WPAT_ShadingType, a) and (a=WPSHAD_solidbg)) then
Result := AGetDefault(WPAT_BGColor, Result);
end;

procedure TWPSetModeControl.SetParColor(x: Integer);
begin
if x <= 0 then
begin
ADel(WPAT_FGColor);
ADel(WPAT_BGColor);
end
else
begin
ADel(WPAT_ShadingType);
ASet(WPAT_FGColor, x);
ASet(WPAT_BGColor, x);
end;
end;

Julian

#4 ♥ 0

Hi,

i am using this to set the par color:

var aColor: TColor;

  aColor := clRed;
  WPRichText.CurrAttr.ParColor := WPRichText.CurrAttr.ColorToNr(aColor, true);
  WPRichText.CurrAttr.ASet(WPAT_ShadingValue, 100);
  WPRichText.ReformatAll();

but still no other color then the default is shown, the paragraph background is alway white.

I use this code with an empty WPRichText directly after the for has been displayed. Are there any options that influence the display of the paragraph color?

What can cause this? (i mean, this code is not that complicated...)

TIA,
Ralf

#5 ♥ 0
support

Hi,

this code worked fine here

WPRichText1.CurrAttr.ParColor := WPRichText1.CurrAttr.ColorToNr(clRed, true);
WPRichText1.CurrAttr.ADel(WPAT_ShadingType);
WPRichText1.CurrAttr.ASet(WPAT_ShadingValue, 50);
WPRichText1.Invalidate();

You should save your text to a WPT file and look at it in notepad.

Julian

#6 ♥ 0

Hi Julian,

i had tried your code with no success.

Then i have completely removed WPTools (BPLs, DCUs, whatever looked like WPTools), reinstalled from scatch and suddenly it works.

I really cannot say what went wrong.

Ciao,
Ralf

#7 ♥ 0
This category is archived. No new posts are possible.