Changing header/footer style in code

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
vit
Posts: 115
Joined: Tue Feb 03, 2009 3:11 pm

Changing header/footer style in code

Post by vit »

Hi! What is the correct way of changing items style in header/footer?

In an example https://drive.google.com/open?id=1hV-fS ... swnvsbJBQs (compiled with v7.2.1 version of SRVE under XE6) try to do these steps:

1. Activate the Header and type any text
2. Deactivate the Header by dbl clicking on main part of the document
3. Push the bStrikeOutHeader
4. Activate the Header again

You're gonna see that as you reactivated the Header in the 4 step, the text there isn't striked out anymore, and the style number of that text is 0 (see in the status bar).

You can see that I create differend TRVStyle objects for each editor:

Code: Select all

  SRVE.ExternalRVStyleHeader := CreateRVS;
  SRVE.ExternalRVStyleFooter := CreateRVS;
  SRVE.ExternalRVStyle := CreateRVS;
I barely remember that there is something connected to SubDocuments for this, but can't remember or find in the the help/forum :(
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Changing header/footer style in code

Post by Sergey Tkachenko »

I am sorry for a late answer, I overlooked this question (

The only reason for using external RVStyles in TSRichViewEdit is ability to define their properties at design time.
It does not make sense to create and assign external RVStyles in code.
You can modify text styles of built-in RVStyles (such as SRVE.RichViewEdit.Style) instead.

However, it does not make sense to create initial set of styles in SRVE.RVHeader.Styles and SRVE.RVFooter.Styles, because SRVE.RVHeader and SRVE.RVFooter contain actual document only when a header/footer is being edited. In all other time (when SRVE is not formatted, or when SRVE.RichViewEdit is being edited), headers and footers are stored in SRVE.SubDocuments[].
If you want to define initial styles in headers footers, assign properties of all SRVE.SubDocuments[].GetRVStyle.TextStyles instead.

Your code for applying changes to the selected editor is overcomplicated.

In StrikeOutAllItems, you can call:

Code: Select all

RVE.SelectAll;
RVE.ApplyStyleConversion(0);
The code in OnStyleConversion should be:

Code: Select all

procedure TForm1.SRVEStyleConversion(Sender: TCustomRichViewEdit; StyleNo,
  UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);
var
  fi: TFontInfo;
begin
  fi := TFontInfo.Create(nil);
  try
    fi.Style := [fsStrikeOut];
    NewStyleNo := ModifyTextStyle(StyleNo, fi, [rvfiStrikeout], Sender.Style);
  finally
    fi.Free;
  end;
end;
Your code in ModifyTextStyle is overcomplicated too. You can simply write:

Code: Select all

procedure TForm1.SRVEStyleConversion(Sender: TCustomRichViewEdit; StyleNo,
  UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);
var
  fi: TFontInfo;
begin
  fi := TFontInfo.Create(nil);
  try
    fi.Assign(Sender.Style.TextStyles[StyleNo]);
    fi.Style := [fsStrikeOut];
    NewStyleNo := Sender.Style.FindTextStyle(fi);
  finally
    fi.Free;
  end;
end;
Post Reply