Edit Line of a Cell

General TRichView support forum. Please post your questions here
Post Reply
jwkerns
Posts: 15
Joined: Sun Mar 05, 2006 11:17 pm

Edit Line of a Cell

Post by jwkerns »

I loop thru and load x number of cells in my richview.
I want to run another loop afterwards and update a line in each cell.
So if I wanted to say add some text to the beginning of the first line how would I do this? Would like an example. Thanks
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Inserting text not at the end of document is not possible using documented methods. Well, I can make an example of inserting text in the beginning of each cell, but may be this will be not what you need.
Can you explain what to you want to implement with more details?
jwkerns
Posts: 15
Joined: Sun Mar 05, 2006 11:17 pm

Actually that will suffice

Post by jwkerns »

Yes that would help.
Basically each cell is loaded with a question. Because we randomly present the questions I don't know the question number before hand.
So after my cells are populated , I reloop thru then and update the current contents.
So for instance , if I have a cell that says 'What is 2 + 2?' then I want to edit the first line in the cell with a question number to look like '1: What is 2 + 2?'.
shmp
Posts: 140
Joined: Sun Aug 28, 2005 10:19 am
Location: Sabah, Malaysia.
Contact:

Post by shmp »

Just an idea.

This is not a very complicated task. You could create a TStringlist for all the questions. Loop through and gather all the questions by adding each one to the StringList and clearing the cells where the question was copied.

Make another loop and this time, random select the question from the TStringList, place it in the cell then delete it from the TStringList.

The next random means that there is less question until the TStringList has only two questions left.

The last question in the TStringList is for the last cell.

By clearing the cells means that you can add the question instead of inserting it.

Hope this idea is good for you.

Good luck.
shmp
Posts: 140
Joined: Sun Aug 28, 2005 10:19 am
Location: Sabah, Malaysia.
Contact:

Post by shmp »

Or you could offset before item then insert the number.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you just need to modify the existing text (not to insert new paragraphs or text of different font), it is very simple.

This code adds numbers to the first columns of each table in the document (nested tables are ignored).

Code: Select all

var i, r, idx: Integer;
     table: TRVTableItemInfo;

for i := 0 to rv.ItemCount-1 do
  if rv.GetItemStyle(i)=rvsTable then begin
    table := TRVTableItemInfo(rv.GetItem(i));
    idx := 1;
    for r := 0 to table.RowCount-1 do
      if (table.Cells[r,0]<>nil) and
        (table.Cells[r,0].GetRVData.GetItemStyle(0)>=0) then begin
        s := table.Cells[r,0].GetRVData.GetItemTextA(0);
        table.Cells[r,0].GetRVData.SetItemTextA(0, IntToStr(idx)+': '+s);
        inc(idx);
      end;
  end;
rv.Format;
Post Reply