export TPanel as shortCode and import back

General TRichView support forum. Please post your questions here
Post Reply
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

export TPanel as shortCode and import back

Post by elGringo »

Good time, Sergey! In other post
https://www.trichview.com/forums/viewto ... 515#p33515
i tried to export/import audio video to HTML and back, and finished on text variant.

Nowadays situation. Having TSRVPanel inserted in TSRichViewEdit.
I want to
1. export it to HTML as some shortcode, lets say like this [SRVPanel]
2. import it from HTML to RVE

What could be an idea of doing this?

For the 1. i tried following approach - to handle SRichViewEditSaveItemToFile - but it doesn't work - HTML always empty - if I write simple text like '123'

Code: Select all

procedure TTestReportConstructor.SRichViewEditSaveItemToFile(Sender: TCustomRichView; const Path: string;
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat; Unicode: Boolean; var OutStr: TRVRawByteString;
  var DoDefault: Boolean);
begin

// if control
if (RVData.GetItemStyle(ItemNo)>=-5) then begin
OutStr:=RVData.GetItemTag(ItemNo);
end else
OutStr:=AnsiToUtf8((OutStr));
DoDefault := False;

end;
For 2. have no idea - on which event I could change [SRVPanel] to control TSRVPanel

Could you give an idea how to realize it?
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: export TPanel as shortCode and import back

Post by elGringo »

Ok, this code saves controls and text but doesn't save any other non-text items (for example tables) - how to fix it? Does it mean that all other non text items shoud be handled manually?
http://www.trichview.com/help/index.htm ... hview.html
A lot of them (

I need manual handling only for controls

Code: Select all

procedure TTestReportConstructor.SRichViewEditSaveItemToFile(
  Sender: TCustomRichView;
  const Path: string;
  RVData: TCustomRVData;
  ItemNo: Integer;
  SaveFormat: TRVSaveFormat;
  Unicode: Boolean;
  var OutStr: TRVRawByteString;
  var DoDefault: Boolean);

var itemText:string;

begin

// if control
if (RVData.GetItemStyle(ItemNo)=rvsComponent) then //begin
OutStr:=RVU_GetRawUnicode( RVData.GetItemTag(ItemNo) ) else
// if text
if RVData.GetItemStyle(ItemNo)>=0 then
begin
itemText:=RVData.GetItemText(ItemNo);
OutStr:=RVU_GetRawUnicode(itemText);
end;

DoDefault:=false;


end;

Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: export TPanel as shortCode and import back

Post by Sergey Tkachenko »

1) There is a special event for saving components to a file, OnSaveComponentToFile
Since the last update, it includes two hidden parameters: Sender.Style.RVData and Sender.Style.ItemNo.
So you can get the item text as TCustomRVData(Sender.Style.RVData).GetItemText(Sender.Style.ItemNo)

2) If you use OnSaveItemToFile for saving controls, the code in it must be like this:

Code: Select all

if (SaveFormat = rvsfHTML) and (RVData.GetItemStyle(ItemNo)=rvsComponent) then
begin
  OutStr:= ...
  DoDefault:=false;
endș
Your code assigns DoDefault = False for all item types, not only for controls; and for all saving formats.
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: export TPanel as shortCode and import back

Post by elGringo »

Solved through OnSaveComponentToFile
Post Reply