I've got List index out of bounds(0) err, please help solve

General TRichView support forum. Please post your questions here
Post Reply
desiki
Posts: 4
Joined: Thu Sep 17, 2009 10:14 am

I've got List index out of bounds(0) err, please help solve

Post by desiki »

Hello everybody,

shortly about my problem: i've got rtf document, containing unique named tagged elements like {Date}, {Name}, used to be replaced with real data when needed. This is template docs.

Also, template document may contain tables, like this (here i'm using "],[" brackets to define cells):

[ Client fullname ] [ Client Birthday ]
[ {client:row} {client.name} ] [ {client.bday} ]

statement {*:row} means current row to be cloned during inserting for ex. a dataset into a table.

So, during parsing this template document, at moment of finding {*: trow} element, i'm trying to copy this row n-times by calling such func

Code: Select all

function makeRowCopy(_table: TRVTableItemInfo; row, n: integer): integer;
var
    Stream: TMemoryStream;
    o: integer;
begin
      Stream := TMemoryStream.Create;
      _table.SaveRowsToStream(Stream, row, 1);
      Stream.Position := 0;
      _table.InsertRows(row + 1, n, 0, False);
      for o := 1 to n do
        _table.LoadFromStreamEx(Stream, row + o);
      Stream.Free;
end;

which raises an exception.
Please, if you have an idea where my way is incorrect, be so kind, tell me =)
Thanks.

P.s. this may be important: algorithm of parsing document is recursive, and looks like:

Code: Select all


procedure parseblock(rv: TCustomRVData)
begin 

for Ix := 0 to rv.ItemCount - 1 do
    if rv.GetItemStyle(Ix) = rvsTable then begin
       table := TRVTableItemInfo(rvd.GetItem(ix));

          for r := 0 to table.Rows.Count - 1 do
               begin

                  headerTag := GetRowTag(table, r); 

                     if pos( ':row', headerTag) > 0 then begin
                           //here i call row clone func and :
                           for c := 0 to table.Rows[r].count - 1 do
                               parseblock(table.cells[r + step, c].GetRVData);
                     end else
                     begin
                      for c := 0 to table.Rows[r].Count - 1 do
                          if table.Cells[r, c] <> nil then
                            RenderBlock(table.Cells[r, c].GetRVData);
                     end;


               end;

    end
    else 
    if rv.GetItemStyle(Ix) >= 0 then begin //just text
         // here i'm replacing tag with data
    end;

end;

Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you send me a simple project reproducing this problem?
Post Reply