Text from Edit to itemtext in table

General TRichView support forum. Please post your questions here
Post Reply
Roman2807
Posts: 7
Joined: Tue Aug 03, 2010 7:25 pm

Text from Edit to itemtext in table

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Roman2807
Posts: 7
Joined: Tue Aug 03, 2010 7:25 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply