TRichView very primitive example for newbie

General TRichView support forum. Please post your questions here
Post Reply
abaloush
Posts: 2
Joined: Thu Oct 12, 2023 7:58 pm

TRichView very primitive example for newbie

Post by abaloush »

I recently purchased Trichview.
For 2 weeks, I could not till now view a docx file stored in Application folder in my android device.
I need a simple and example code of how to do that.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView very primitive example for newbie

Post by Sergey Tkachenko »

If DocX file (let its name is 'example.docx') is deployed to assets\internal, you can load it as:

Code: Select all

uses System.IOUtils;

var
  FileName: String;
begin
  FileName := IncludeTrailingPathDelimiter(System.IOUtils.TPath.GetDocumentsPath) + 'example.docx';
  RichViewEdit1.Clear;
  RichViewEdit1.LoadDocX(FileName);
  RichViewEdit1.Format;
end;
This example assumes that you placed RichViewEdit1: TRichViewEdit and RVStyle1: TRVStyle on the form, and assigned RichViewEdit1.Style = RVStyle1.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView very primitive example for newbie

Post by Sergey Tkachenko »

Also, you can check demo projects in <TRichView Dir>\Demos\Delphi.FMX\ folder.
For example, "Editors\Editor 2\" demo.
Editor demos allow opening files (including DocX files) from common location of Android device.
The procedure is slightly more difficult than opening application-local files: a file choosing dialog returns not a file name, but file URL.
Details of file choosing on Android and iOS are described here: https://www.trichview.com/forums/viewtopic.php?t=11960
(this topic is in the protected section of this forum, I opened access for your account).
abaloush
Posts: 2
Joined: Thu Oct 12, 2023 7:58 pm

Re: TRichView very primitive example for newbie

Post by abaloush »

Sergey Tkachenko wrote: Thu Oct 12, 2023 8:56 pm Also, you can check demo projects in <TRichView Dir>\Demos\Delphi.FMX\ folder.
For example, "Editors\Editor 2\" demo.
Editor demos allow opening files (including DocX files) from common location of Android device.
The procedure is slightly more difficult than opening application-local files: a file choosing dialog returns not a file name, but file URL.
Details of file choosing on Android and iOS are described here: https://www.trichview.com/forums/viewtopic.php?t=11960
(this topic is in the protected section of this forum, I opened access for your account).
Thank you.
It warked. The problem now it did not display right2left arabic unicode correctly, though I selected unicode in the rvstyle.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView very primitive example for newbie

Post by Sergey Tkachenko »

"Unicode" property of text styles is an obsolete property, it does nothing, all text is always Unicode.

1) Probably, to display your file properly, you should define the main text direction in the document.
Assign RichViewEdit1.BiDiMode = rvbdRightToLeft to set RTL direction, or rvbdLeftToRight to set LTR direction.
Do it before loading DocX. Some bi-di properties are not loaded from DocX is BiDiMode = rvbdUnspecified.

2) To make sure that all DocX properties are loaded. Right click RichViewEdit1 at design time, choose "Settings" in the popup menu.
To load all DocX text and paragraph properties, the setting on the first page must be "Allow adding styles dynamically" or "Allow adding styles dynamically + StyleTemplates".
Post Reply