Samples to work with tables without rvActions

General TRichView support forum. Please post your questions here
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Samples to work with tables without rvActions

Post by Marsianin »

I'm removing rvActions from my project and found some troubles with tables...

Is there any samples on how to detect if cursor is inside the table, adding/removing rows/cols, justifying etc.

I found almost everything in RichViewActions.pas but some things are not clear and working different.

Why I can't use table.DeleteSelectedRows directly?

Why there are a lot of Access Violations (not always and try...except helps) when starting to type letters in empty cells, removing rows/cols?

How to check if current item is a table?

Also with code from rvActions my toolbar DeleteCols/Rows buttons are enabled only if whole Col/Row is selected but in rvActions have cursor inside the table is enough.

Code: Select all

  rve:=TCustomRichViewEdit(RichViewEdit1.RVData.GetAbsoluteRootData.GetParentControl);
  if rve.GetCurrentItemEx(TRVTableItemInfo,rve,item) then begin
    table:=TRVTableItemInfo(item);
    boo:=True;          // We're inside the table, but it's not for 100%
    if table.GetNormalizedSelectionBounds(True,a,b,c,d) then begin
      if d=table.Rows.Count then bo1:=True;    //TrvActionTableDeleteCols
      if c=table.Rows[0].Count then bo2:=True; //TrvActionTableDeleteRows
    end;
    if table.CanMergeSelectedCells(True) then bo3:=True else bo4:=True;
  end;
What is TrvActionFillColor ?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

For table operations, see the demo in
Editors\Editor 1, menu Table.

Info: http://www.trichview.com/help/idto_tabl ... tions.html
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Thanks, I found the samples I need but still have some problems:

Why this code raises error with List Index Out of Bounds (-1) right after RichViewEdit1.Clear ?

Code: Select all

if RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo,rve,item) then begin
...
I have this code on OnCurTextStyleChanged;

Also why RichViewEdit1..Clear fires OnCurTextStyleChanged a lot of times while clearing document?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

GetCurrentItemEx requires formatted document.
Add a check

Code: Select all

if RichViewEdit1.ItemCount=0 then
  exit;
Multiple calls? Probably Clear calls it once (or more than once, if the caret was in a table), then Format can call it.

The proper place to update UI for tables is OnCaretMove event.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Tried if RichViewEdit1.ItemCount=0 then exit; already. Didn't help.
Will try to move updating table UI to OnCaretMove.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Ok, moved it to OnCaretMove and it works.
But still have some troubles:

1. How to find out if current cell can be splitted to original cells to enable/disable corresponding RadioButton (as in rvActions dialog).

2. How to find out if I split to original cols/rows is allowed to enable/disable corresponding CheckBoxes.

3. This code fires List Index Out Of Bound (-1) for 6-7 times but finally merges cells:

Code: Select all

      rve.BeginItemModify(ItemNo,Data);
      begin  // Merge cells
        rve.BeginUndoGroup(rvutModifyItem);
        rve.SetUndoGroupMode(True);
        try
          boo:=table.GetNormalizedSelectionBounds(True,r,c,cs,rs);
          table.MergeSelectedCells(True);
          table.DeleteEmptyRows;
          table.DeleteEmptyCols;
          if boo then table.Select(r,c,0,0);
        finally
          rve.SetUndoGroupMode(False);
        end;
      end;
      rve.EndItemModify(ItemNo,Data); <<<<< ERROR APPEARS HERE
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for disabling/enabling UI for table operations, see the same demo, TForm1.mpdTableClick.

As for the error, please give me step-by-step instructions how to reproduce.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

That demo contains different menu items than demo with rvActions and there is no Split Cells dialog there.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This demo does not have this dialog, but its commands are implemented as menu items:
Table | Split submenu
Table | Unmerge submenu
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Unmerge menu items are always enabled even if there is nothing to unmerge.
Sample from rvActions works but I'm getting access violation running this code right after using table.UnmergeSelectedCells(CheckBox3.Checked,CheckBox2.Checked):

Code: Select all

  boo:=table.GetNormalizedSelectionBounds(True,r,c,cs,rs);
  if boo then begin
    bo1:=table.CanMergeSelectedCells(True);
    bo2:=(table.CanMergeSelectedCells(True)or(table.GetEditedCell(r,c)<>nil));
    table.Rows.GetMainCell(r,c,r,c);
    SplitCellsOrig := (cs = table.Cells[r,c].ColSpan) and
                            (rs = table.Cells[r,c].RowSpan);
    SplitCellsOrig := SplitCellsOrig or table.CanMergeSelectedCells(True);
  end;
Another problem appeared when I moved UptadeToolbarUI routine to rveOnCaretMove because while modifying table that event occurred. But this fixed with a simple flag.
Nut after table manipulations I have to update toolbars and calling rveCaretMove(self) raises access violation in table.Rows.GetMainCell(r,c,r,c); in the code above.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please send me a simple project to reproduce this problem.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

My project is not simple.

But I think that problematic code fires some event which cannot be processed on that stage. I'm going to study it.

Maybe you can help me to check what events fires this code from rvActions?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Find the line of TRichView code that raises the exception, and a call stack at the moment of the exception.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

It seems I found a bug with tables in the latest RichViewEdit.
To reproduce:

1. Open RichViewEdit Editor Demo 1
2. Insert Table Example 2
3. Delete text and button
4. Unmerge (rows and cols) that cell were was a button
5. You'll get a clear 6x10 table
6. Select full rows beginning from 2 to 7, merge them
7. Try to unmerge just merged cells with original rows and cols
8. Original amount of rows is lost

P.S. Found an event which produced error while splitting cells to original rows/cols but still sometimes I'm getting Accss Violation splitting cells and debugger doesn't stops - just popup message (in debug configuration of course)
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) You can see that the demo calls table.DeleteUnusedCols and table.DeleteUnusedRows after cell merging. These methods delete "ghost" columns and rows (consisting only of nil-cells). Such columns/rows could confuse the user. However, as you can see, the number of columns/rows is changed.

2) Sorry, without knowing your code I cannot help. If you will be able to reproduce on trichview demos, or if you can create a simple project reproducing this problem, let me know.
Post Reply