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
Overwrite font of a range when inserting tags
-
- Posts: 3
- Joined: Tue Nov 14, 2006 10:42 am
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
You cannot, because text style defines all font properties.
But you can create protected style with the desired attributes:
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;