Page 1 of 1

Text from Edit to itemtext in table

Posted: Tue Aug 17, 2010 1:41 pm
by Roman2807
My code:

Code: Select all

procedure TForm8.Edit2Change(Sender: TObject);
var t : TRVtableitemInfo;
    s : trvtextiteminfo;
    i, i1 : integer;
begin
  t := (SRichViewEdit1.RichViewEdit.RVData.Items.Objects[0] as TRVtableItemInfo);
  t.Cells[0, 0].SetItemText((sender as tedit).Tag, (sender as tedit).Text);
  t.EditCell(0, 0);
  SRichViewEdit1.RichViewEdit.SetFocus;
  edit2.SetFocus;
  Edit2.SelLength := 0;
  edit2.SelStart := length(edit2.Text);
end;
By the second pressing of a key there is an error: list index out of bounds (1)

How it to avoid?

Posted: Tue Aug 17, 2010 2:55 pm
by Sergey Tkachenko

Code: Select all

t := (SRichViewEdit1.RichViewEdit.GetItem(0) as TRVtableItemInfo); 
t.Cells[0, 0].GetRVData.SetItemText((sender as tedit).Tag, (sender as tedit).Text); 
SRichViewEdit1.RichViewEdit.Format;
t.EditCell(0, 0); 
1) I use Cell[0,0].GetRVData instead of Cell[0,0] to access items. Without GetRVData, this code will work correctly only if this cell is not being edited.
2) I added call of Format, it is required after calling a non-editing method like SetItemText.
3) Additionaly, you should call SRichViewEdit1.RichViewEdit.ClearUndo, because calling non-editing method can make data in undo/redo buffers invalid.

Posted: Tue Aug 17, 2010 3:59 pm
by Roman2807
Has solved a problem so:

Code: Select all

  t := (SRichViewEdit1.RichViewEdit.RVData.Items.Objects[0] as TRVtableItemInfo);
  s := (sender as tedit).Text;
  t.EditCell(0, 0);
  t.FInplaceEditor.SetItemText((sender as tedit).Tag, s);
But, SetItemText insert the text without last symbol, and at text removal (by pressing backspace or delete) all is good

Posted: Tue Aug 17, 2010 4:15 pm
by Sergey Tkachenko
Format is required after SetItemText.
Or you can use SetItemTextEd instead of SetItemText. This is an editing method, it updates document itself.