Page 1 of 1

export TPanel as shortCode and import back

Posted: Fri Aug 04, 2017 3:42 pm
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?

Re: export TPanel as shortCode and import back

Posted: Fri Aug 04, 2017 4:36 pm
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;


Re: export TPanel as shortCode and import back

Posted: Fri Aug 04, 2017 6:11 pm
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.

Re: export TPanel as shortCode and import back

Posted: Sat Aug 05, 2017 7:50 am
by elGringo
Solved through OnSaveComponentToFile