Page 1 of 1

Programatically Delete a table

Posted: Mon Mar 19, 2007 8:17 pm
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.

Posted: Tue Mar 20, 2007 1:59 pm
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;

Posted: Wed Mar 21, 2007 12:48 pm
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).

Posted: Thu Mar 22, 2007 3:32 pm
by Sergey Tkachenko
I think that this error is caused by another code.

Posted: Thu Mar 22, 2007 4:56 pm
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]

Posted: Thu Mar 22, 2007 5:32 pm
by Sergey Tkachenko
Do you use TRichView or TRichViewEdit?
If TRichViewEdit, why?

Posted: Thu Mar 22, 2007 5:55 pm
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.

Posted: Fri Mar 23, 2007 7:53 am
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.