editing tables problem

General TRichView support forum. Please post your questions here
Post Reply
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

editing tables problem

Post by Cosmin3 »

Hi.
I use this code to create a RichViewEdit in a separate thread:

Code: Select all

      FRVStyle := TRVStyle.Create(nil);
      FRVStyle.Name := 'Style';
      FRichViewEdit := TRichViewEdit.Create(FFormOwner);
      with FRichViewEdit do
      begin
         ReadOnly := False;
         Parent := FFormOwner;
         Name := 'RVComponent';
         Style := FRVStyle;
         Color := clWhite;
         Options := [rvoAllowSelection, rvoScrollToEnd, rvoTagsArePChars,
            rvoAutoCopyText, rvoAutoCopyRVF, rvoAutoCopyImage,
            rvoAutoCopyRTF, rvoFormatInvalidate, rvoDblClickSelectsWord,
            rvoRClickDeselects];
         RTFReadProperties.UnicodeMode := rvruOnlyUnicode;
         RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
         RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
         RVFOptions := [rvfoLoadDocProperties, rvfoSaveDocProperties,
            rvfoSavePicturesBody, rvfoSaveControlsBody,
            rvfoIgnoreUnknownPicFmt, rvfoIgnoreUnknownCtrls,
            rvfoConvUnknownStylesToZero, rvfoConvLargeImageIdxToZero,
            rvfoSaveBinary, rvfoSaveBack, rvfoLoadBack,
            rvfoSaveTextStyles, rvfoSaveParaStyles, rvfoSaveLayout,
            rvfoLoadLayout];
         RTFOptions := [rvrtfSaveDocParameters, rvrtfDuplicateUnicode];
         RTFReadProperties.ReadDocParameters := True;
         Visible := True;
         UndoLimit := 0;
         Format;
         BeginUpdate;
         Clear;
      end;
FFormOwner is in main thread and is not visible.
I load a rtf using LoadRTFFromStream or PasteRTF. The text from RootEditor and/or table cells is modified and then the document is copied back into stream or Clipboard. All is done automatically.
The problem is that with the last version of TRichViewEdit every time I try to enter in edit mode at any table cell the program frezees. A few month ago it didn't do that.
I tried to debug the problem but in RVTInplace.pas I lost "track"...
I can't use a previous version because it has other problems...

I'd appreciate any sugestion.
Thank you in advance.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I do not recommend to create or edit document in a separate thread. Use Synchronize method to execute this code in the context of the main process.
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

Thank you for the quick reply.
I understand but it's very important to be executed in a separate thread.
Besides, like I said, it worked well until a few months ago.

By the way, is there a viewer style method to change/delete items so I wouldn't have to use Edit + SetSelectionBounds + InsertText?
For changes in text (in an item) I use Cell.SetItemText but sometimes I need to convert a tab item in a text item or a text item in text items + tab items...
I don't need Undo.
Anyway without Edit the hole operation it will be faster.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

ItemText

Post by Sergey Tkachenko »

I am afraid I cannot guarantee correct work if creating/changes are made in thread.

For deletion, you can use DeleteItems. But make sure that documents remain valid: http://trichview.com/help/valid_documents.html .
As for viewer-style insertion, there is no documented methods.

You can use the following code for inserting tab:

Code: Select all

var item: TRVTabItemInfo;
  s: TRVRawByteString;

item := TRVTabItemInfo.Create(rv.RVData);
item.StyleNo := rvsTab;
item.TextStyleNo := ...;
item.ParaNo := ...;
item.SameAsPrev := True; // if this item continues the paragraph
s := '';
item.Inserting(rv.RVData, s, False);
RVData.Items.InsertObject(ItemNo, s, item);
item.Inserted(rv.RVData, ItemNo);
For string

Code: Select all

// Converting text from String to internal representation
function ConvertStringToItemText_(const Text: String;
  UnicodeItem: Boolean; CodePage: Cardinal): TRVRawByteString;
begin
  {$IFDEF RVUNICODESTR} // <-- declared in RV_Defs.inc
  if UnicodeItem then
    Result := RVU_GetRawUnicode(Text)
  else
    Result := TRVAnsiString(Text);
  {$ELSE}
  {$IFNDEF RVDONOTUSEUNICODE}
  if UnicodeItem then
    Result := RVU_AnsiToUnicode(CodePage, Text)
  else
  {$ENDIF}
    Result := Text;
  {$ENDIF}
end;

function ConvertStringToItemText(const Text: String;
  RVData: TCustomRVData; StyleNo: Integer): TRVRawByteString;
begin
  Result := ConvertStringToItemText_(Text, RVData.GetRVStyle.TextStyles[StyleNo].Unicode, RVData.GetStyleCodePage(StyleNo));
end;

var item: TRVTextItemInfo;
  s: TRVRawByteString;

item := RichViewTextItemClass.Create(rv.RVData);
item.StyleNo := ...;
item.ParaNo := ...;
item.SameAsPrev := True; // if this item continues the paragraph
s := ConvertStringToItemText(..., rv.RVData, item.StyleNo);
if rv.Style.TextStyles[item.StyleNo].Unicode then
  item.ItemOptions := item.ItemOptions+[rvioUnicode];
item.Inserting(rv.RVData, s, False);
RVData.Items.InsertObject(ItemNo, s, item);
item.Inserted(rv.RVData, ItemNo);
I am sorry if this code looks complicated. Probably in future I'll create a new unit containing viewer-style methods for inserting items.
I typed this code in browser, so misprints are possible.
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

Thank you for your help.
I will try this code.
Post Reply