Programatically Delete a table

General TRichView support forum. Please post your questions here
Post Reply
Fishous
Posts: 7
Joined: Mon Mar 19, 2007 1:27 pm

Programatically Delete a table

Post by Fishous »

I'm using TRichViewEdit as a chat history display. I'm inserting each entry in as an HTML Table that simply has one row, two cells. Picture in the left cell, text in the right.

I need to programatically delete the first table in the document. I can't figure out how to do it.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This code assumes that the document is formatted. Do not call rv.Format after it - it's not required.

Code: Select all

For i := 0 to rv.ItemCount-1 do
  if rv.GetItemStyle(i)=rvsTable then begin
    rv.DeleteParas(i,i);
    break;
  end;
Fishous
Posts: 7
Joined: Mon Mar 19, 2007 1:27 pm

Post by Fishous »

What happens when you put rv.ReadOnly := false before that code, and rv.ReadOnly := true right after it?

I get an index out of bounds error in TCustomRichViewEdit.SetReadOnly, on the Invalidate line (i think).
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I think that this error is caused by another code.
Fishous
Posts: 7
Joined: Mon Mar 19, 2007 1:27 pm

Post by Fishous »

I fixed it by doing a format:

Code: Select all

        For i := 0 to FRichView.ItemCount - 1 do begin
          if FRichView.GetItemStyle(i) = rvsTable then begin
            FRichView.DeleteParas(i,i);
            dec(FChatEntries);
            FRichview.Format;
            break;
          end;
        end; //for
[/code]
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you use TRichView or TRichViewEdit?
If TRichViewEdit, why?
Fishous
Posts: 7
Joined: Mon Mar 19, 2007 1:27 pm

Post by Fishous »

Oh, yeah, FRichView is a TRichViewEdit. Originally it was a TRichView, but there was something it couldn't do that the edit could, but I can't remember what exactly.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Probably the error is because of mixing use of editing and not editing operations (editing-style and viewer-style methods)
Try to convert it back to TRichView, may be I can suggest how to implement that "something" in TRichView instead of editor.
Post Reply