Page 1 of 1

Overwrite font of a range when inserting tags

Posted: Fri May 04, 2007 5:15 pm
by Toni Santa
Hi,
I've a style (FieldStyle) with ModifyProtect = true; when inserting 'Fields' (InsertStringTag..) this style is applied first (CurTextStyleNo = noFieldStyle). Now I would have the need that the inserted 'tags' (fields) are automatically formatted with the same font as it has the position (range) where I'm inserting. How can this be applied without loosing the 'FieldStyle' of the inserted tag?
best regards
Toni

Posted: Tue May 08, 2007 6:03 pm
by Sergey Tkachenko
You cannot, because text style defines all font properties.
But you can create protected style with the desired attributes:

Code: Select all

function GetProtectedStyle(RVStyle: TRVStyle; StyleNo: Integer): Integer;
var TextStyle: TFontInfo;
begin
  TextStyle := TFontInfo.Create(nil);
  try
    TextStyle.Assign(RVStyle.TextStyles[StyleNo]);
    TextStyle.Protection := [rvprModifyProtect {,rvprDoNotAutoSwitch}];
    Result := RVStyle.TextStyles.FindSuchStyle(StyleNo, TextStyle, RVAllFontInfoProperties);
    if Result<0 then begin
      RVStyle.TextStyles.Add;
      Result := RVStyle.TextStyles.Count-1;
      RVStyle.TextStyles[Result].Assign(TextStyle);
      RVStyle.TextStyles[Result].Standard := False;
    end;
  finally
    TextStyle.Free;
  end;
end;

OldStyleNo := rve.CurTextStyleNo;
rve.CurTextStyleNo := GetProtectedStyle(rve.Style, OldStyleNo);
rve.InsertStringTag(...);
rve.CurTextStyleNo := OldStyleNo;