I'am always studying the TrichViewEdit component.
I have find two way to change by code (without using Taction) the text color of the selected text.
Which is the better one ? Maybe it's exists a better way ?
Code: Select all
procedure ChangeSelectedTextColor(ARichViewEditTarget: TCustomRichViewEdit; AColor: TColor);
var
LNewStyleNo, LExistingStyleNo: Integer;
LStyle: TFontInfo;
LRVStyle: TRVStyle;
begin
if not ARichViewEditTarget.CanChange then Exit;
LRVStyle := ARichViewEditTarget.Style;
LNewStyleNo := LRVStyle.TextStyles.Count;
LStyle:=LRVStyle.TextStyles.Add;
LStyle.Assign(LRVStyle.TextStyles[ARichViewEditTarget.CurTextStyleNo]);
LStyle.Color := AColor;
ARichViewEditTarget.ApplyTextStyle(LNewStyleNo);
end;
Code: Select all
procedure ChangeSelectedTextColor(ARichViewEditTarget: TCustomRichViewEdit; AColor: TColor);
var
LNewStyleNo, LExistingStyleNo: Integer;
LStyle: TFontInfo;
LRVStyle: TRVStyle;
begin
if not ARichViewEditTarget.CanChange then Exit;
LRVStyle := ARichViewEditTarget.Style;
LNewStyleNo := LRVStyle.TextStyles.Count;
LStyle := TFontInfo.Create(nil);
try
LStyle.Assign(LRVStyle.TextStyles[ARichViewEditTarget.CurTextStyleNo]);
LStyle.Color := AColor;
LRVStyle.TextStyles.Add.Assign(LStyle);
finally
LStyle.Free;
end;
ARichViewEditTarget.ApplyTextStyle(LNewStyleNo);
end;