Page 1 of 1
Add a text item at the beginning of a TRichView
Posted: Tue Jun 19, 2007 2:32 pm
by jonjon
I must be blind (and never needed it before) but I can't seem to find out how to add an item at the beginning of a formatted TRichView.
My problem is that I was adding the item for the header, then inserting another TRichView's content, then adding an item for the footer. But when I inserted the TRichView, I lost the background information so now I'm loading the TRichView then adding the footer and... I can't find how to add the header above everything else
Thank you for any help.
John.
Posted: Wed Jun 20, 2007 1:24 pm
by Sergey Tkachenko
Yes, there is only one documented method allowing to add content at the specified place in TRichView: InsertRVFFromStream.
Using undocumented methods, you can insert text item at the specified position using this code:
Code: Select all
use RVItem;
procedure InsertText(rv: TCustomRichView; ItemNo: Integer; const s: String; StyleNo, ParaNo: Integer);
var item: TRVTextItemInfo;
begin
item := RichViewTextItemClass.Create(RVData);
item.StyleNo := StyleNo;
item.ParaNo := ParaNo;
item.Inserting(rv.RVData, s, False);
rv.RVData.Items.InsertObject(ItemNo, s, item);
item.Inserted(rv.RVData, ItemNo);
end;
Using to insert at the beginning:
InsertText(RichView1, 0, 'Title', StyleNo, ParaNo);
This code assumes that rv.Style.TextStyles[StyleNo].Unicode = False. If you need code for Unicode text, let me know.
Posted: Sun Jun 24, 2007 6:17 pm
by jonjon
Thank you Sergey,
I'm sorry but I will also need the unicode version as I have no way of knowing if the user added ANSI or unicode text to the header.
Thank you very much.
Best regards,
John.
Posted: Mon Jun 25, 2007 7:04 am
by Sergey Tkachenko
Code: Select all
uses CRVData, RVUni;
procedure InsertText(rv: TCustomRichView; ItemNo: Integer; s: String; StyleNo, ParaNo: Integer);
var item: TRVTextItemInfo;
begin
item := RichViewTextItemClass.Create(RVData);
item.StyleNo := StyleNo;
item.ParaNo := ParaNo;
if rv.Style.TextStyles[StyleNo].Unicode then begin
s := RVU_AnsiToUnicode(rv.RVData.GetStyleCodePage(StyleNo), s);
item.ItemOptions := item.ItemOptions+[rvioUnicode];
end;
item.Inserting(rv.RVData, s, False);
rv.RVData.Items.InsertObject(ItemNo, s, item);
item.Inserted(rv.RVData, ItemNo);
end;
Or, if you want WideString parameter
Code: Select all
procedure InsertTextW(rv: TCustomRichView; ItemNo: Integer; const s: WideString; StyleNo, ParaNo: Integer);
var item: TRVTextItemInfo;
s2: String;
begin
item := RichViewTextItemClass.Create(RVData);
item.StyleNo := StyleNo;
item.ParaNo := ParaNo;
if rv.Style.TextStyles[StyleNo].Unicode then begin
s2 := RVU_GetRawUnicode(s);
item.ItemOptions := item.ItemOptions+[rvioUnicode];
end
else
s2 := RVU_UnicodeToAnsi(rv.RVData.GetStyleCodePage(StyleNo), RVU_GetRawUnicode(s));
item.Inserting(rv.RVData, s2, False);
rv.RVData.Items.InsertObject(ItemNo, s2, item);
item.Inserted(rv.RVData, ItemNo);
end;
Posted: Mon Jun 25, 2007 6:52 pm
by jonjon
Thank you very much Sergey,
I will try that as soon as possible.
Best regards,
John.