Copying table data from clipboard into RichView table

General TRichView support forum. Please post your questions here
Post Reply
Primvs
Posts: 7
Joined: Tue Oct 25, 2005 1:46 pm

Copying table data from clipboard into RichView table

Post by Primvs »

Hi!

RichViewEdit's default behaviour when copying table (Excel/Word) from clipboard into table seems to be creating new table inside currently edited table cell.

Is there a simple way to copy table data from clipboard into richview table cell by cell?

I tried to bypass the problem by using template, hidden RichViewEdit, into which I paste data from clipboard, search for table, than try to copy cell data for each cell from template RichViewEdit to visible RichViewEdit. It throws "access violation" in one of the richview units (it does not happen in procedure bellow nor in any of my units). Can anybody tell me what am I doing wrong?

My RichView version is 1.9.15

LP, Primoz

p.s. I call following procedure in OnPaste event of RichViewEdit, after setting DoDefault variable to false.

Code: Select all

procedure TfmeTableNew.PasteExcelTableDataIntoRVTable;
var
  tmpTable: TRVTableItemInfo;
  tmpTablePasted: TRVTableItemInfo;
  intRow, intCol: integer;
  intRowIndex, intColIndex: integer;
  MS: TMemoryStream;
  oldps, oldts: TRVFReaderStyleMode;
  UnusedColor: TColor;
begin
  UnusedColor := clNone;
  rve.BeginUpdate;
  try
    try
      tmpRVE.Clear;
      tmpRVE.Paste;
      tmpTable := GetTableObject(rve);
      tmpTablePasted := GetTableObject(tmpRVE);
      if tmpTable = nil then exit
      else begin
        if (tmpTable.GetEditedCell(intRow, intCol)) <> nil then begin
          if tmpTablePasted <> nil then begin
            oldps := rve.RVFParaStylesReadMode;
            oldts := rve.RVFTextStylesReadMode;
            rve.RVFParaStylesReadMode := rvf_sIgnore;
            rve.RVFTextStylesReadMode := rvf_sIgnore;
            SendMessage(rve.Handle, WM_SETREDRAW, 0, 0);
            try

              intRowIndex := 0;
              while intRowIndex < tmpTablePasted.Rows.Count do begin
                intColIndex := 0;
                while intColIndex < tmpTablePasted.Rows[intRowIndex].Count do begin
                  if (tmpTablePasted.Cells[intRowIndex, intColIndex] <> nil) and
                    (tmpTable.Cells[intRow + intRowIndex, intCol + intColIndex] <> nil) then begin
                    MS := TMemoryStream.Create;
                    try
                      tmpTablePasted.Cells[intRowIndex, intColIndex].GetRVData.SaveRVFToStream(ms, False, UnusedColor, nil, nil);
                      ms.Position := 0;
                      tmpTable.Cells[intRow + intRowIndex, intCol + intColIndex].Edit;
                      rve.TopLevelEditor.SelectAll;
                      rve.TopLevelEditor.InsertRVFFromStreamEd(ms);
                    finally
                      MS.Free;
                    end;
                  end;
                  Inc(intColIndex);
                end;
                Inc(intRowIndex);
              end;
            finally
              rve.RVFParaStylesReadMode := oldps;
              rve.RVFTextStylesReadMode := oldts;
              SendMessage(rve.Handle, WM_SETREDRAW, 1, 0);

              while rve <> nil do begin
                rve.Invalidate;
                rve := TRichViewEdit(rve.InplaceEditor);
              end;

            end;
          end
          else begin
            rve.PasteText;
          end;
        end;
      end;
    except
      on e: Exception do
        ShowMessage('Error copying data '+e.Message);
    end;
  finally
    rve.EndUpdate;
    rve.ClearUndo;
  end;
end;
[/code]
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's hard to find bug in such large code in browser.
Please send me a simple project that I can compile to find the problem.
Primvs
Posts: 7
Joined: Tue Oct 25, 2005 1:46 pm

Silly me

Post by Primvs »

Hey Sergey,

sorry for bothering you- I copied only part of the function from one of the posts in this forum, and didn't notice, that rve was a function parameter. So, after my function was completed rve variable was pointing to nil, which of course caused AV.

LP, Primoz
Sergey Tkachenko wrote:It's hard to find bug in such large code in browser.
Please send me a simple project that I can compile to find the problem.
Post Reply