Page 1 of 2

Changing variables

Posted: Tue Jan 11, 2011 4:12 pm
by Ceprotec
Hello Sergey!

I need a formula for SrichView that runs inside the onClick of a button as follows:

1) Find the number of pages

2) Change the variables FiellFields using only the first sheet.

3) performing my procedure of updating of a table.

4) Change the variables FiellFields using only the second page.

5) Run my procedure of updating of a table.

6) Changing the variables FiellFields using only the third leaf.

... and so on until the last page. That is, we have to seek the number of pages, create a While () according to this number, and run the function in FiellFields only selected pages ..

There's how to do this?

Posted: Tue Jan 11, 2011 8:20 pm
by Sergey Tkachenko
PageCount - SRichViewEdit.PageCount.
You can find where the page starts using SRichViewEdit.GetPageStartItemNo.

Posted: Tue Jan 11, 2011 8:30 pm
by Ceprotec
ok but how do I run the function FiellField only on page 1 and stop. Start and stop on page 2. On page 3 and then stop?

Posted: Tue Jan 11, 2011 8:47 pm
by Sergey Tkachenko
I can try to modify an example, but FillFields from which demo do you use?

Posted: Wed Jan 12, 2011 10:07 am
by Ceprotec
I use the following:

FillFields (SRichViewEdit1.RichViewEdit.RVData);

and

Code: Select all

TFrmCadModelos.FillFields procedure (RVData: TCustomRVData);
var i, j, r, c: Integer;
    table: TRVTableItemInfo;
    FieldName, FieldValue: String;
    s: String;
    FieldEnd: Integer;
    Changed: Boolean;
begin
  for i: = 0 to RVData.ItemCount-1
    RVData.GetItemStyle if (i) = rvsTable then begin
      table: = TRVTableItemInfo (RVData.GetItem (i));
      is r: = 0 to table.Rows.Count-1
        is c: = 0 to table.Rows [r]. Count-1
          table.Cells if [r, c] <> nil then
            FillFields (table.Cells [r, c]. GetRVData);
      end
    RVData.GetItemStyle else if (i)> = 0 then begin
      s: = RVData.GetItemText (i);
      FieldEnd: = 0;
      Changed: = False;
      for j: = Length (s) downto 1 do begin
        if s [j ]='}' then
          FieldEnd: = j
        else if (s [j ]='{') and (FieldEnd> 0) then begin
          FieldName: = Copy (s, j +1, FieldEnd-j-1);
          FieldValue: = GetFieldValueFromDatabase (FieldName);
          Delete (s, j, FieldEnd-j +1);
          Insert (FieldValue, s, j);
          FieldEnd: = 0;
          Changed: = True;
        end;
      end;
      if Changed then
        RVData.SetItemText (i, s);
    end;
end;
This procedure would have to run on each page separadamnete so I can run other commands to change page ...

Posted: Thu Jan 13, 2011 10:03 am
by Ceprotec
Sergey any ideas??

Posted: Thu Jan 13, 2011 3:27 pm
by Sergey Tkachenko
Sorry for delay, I'll post code tomorrow.

Posted: Thu Jan 13, 2011 7:12 pm
by Ceprotec
ok ok :)

Posted: Sat Jan 15, 2011 12:12 pm
by Sergey Tkachenko

Code: Select all

procedure TForm3.FillFields (RVData: TCustomRVData; srv: TSRichViewEdit;
   PageNo: Integer);
var i, j, r, c, FirstItemNo, FirstOffs, LastItemNo, LastOffs,
    First, Last: Integer;
    table: TRVTableItemInfo;
    FieldName, FieldValue: String;
    s: String;
    FieldEnd: Integer;
    Changed: Boolean;
begin
  // finding the range of items for processing
  if PageNo<>0 then begin
    // item range on the page
    srv.GetPageStartItemNo(PageNo, FirstItemNo, FirstOffs);
    srv.GetPageLastItemNo(PageNo, LastItemNo, LastOffs);
    end
  else begin
    // RVData completely
    FirstItemNo := 0;
    LastItemNo := RVData.ItemCount-1;
    if RVData.GetItemStyle(FirstItemNo)=rvsTable then
      FirstOffs := 0
    else
      FirstOffs := RVData.GetOffsBeforeItem(FirstItemNo);
    if RVData.GetItemStyle(LastItemNo)=rvsTable then
      LastOffs := TRVTableItemInfo(RVData.GetItem(LastItemNo)).RowCount-1
    else
      LastOffs := RVData.GetOffsAfterItem(LastItemNo);
  end;
  // processing
  for i := LastItemNo downto FirstItemNo do
    if RVData.GetItemStyle(i) = rvsTable then begin
      // tables: calling recursively
      table := TRVTableItemInfo (RVData.GetItem(i));
      if i=FirstItemNo then
        First := FirstOffs
      else
        First := 0;
      if i=LastItemNo then
        Last := LastOffs
      else
        Last := table.RowCount-1;
      for r := First to Last do
        for c := 0 to table.ColCount-1 do
          if  table.Cells[r, c] <> nil then
            FillFields (table.Cells[r, c].GetRVData, srv, 0);
      end
    else if RVData.GetItemStyle(i) >= 0 then begin
      // text
      s := RVData.GetItemText (i);
      FieldEnd := 0;
      Changed := False;
      if i=FirstItemNo then
        First := FirstOffs
      else
        First := 1;
      if i=LastItemNo then
        Last := LastOffs-1
      else
        Last := Length(s);
      for j := Last downto First do begin
        if s[j]='}' then
          FieldEnd := j
        else if (s [j ]='{') and (FieldEnd> 0) then begin
          FieldName := Copy (s, j +1, FieldEnd-j-1);
          FieldValue := GetFieldValueFromDatabase (FieldName);
          Delete (s, j, FieldEnd-j +1);
          Insert (FieldValue, s, j);
          FieldEnd := 0;
          Changed := True;
        end;
      end;
      if Changed then
        RVData.SetItemText (i, s);
    end;
end;
Example of using:

Code: Select all

  FillFields(SRichViewEdit1.RichViewEdit.RVData, SRichViewEdit1, 1);
  SRichViewEdit1.Format;
Note 1: If you do not call SRichViewEdit1.Format, you will not be able to process the next page correctly.
Note 2: I suggest to call this function in backward direction, from SRichViewEdit1.PageCount downto 1.
Note 3: After replacing fields with values, document may be separated to pages in different places.
Note 4: when, in future, we implement page breaks inside table cells for TSRichViewEdit, this code will be not completely correct, because it will be not enough to use GetPageStartItemNo/GetPageLastItemNo to find the first/last row on the page.

Posted: Sat Jan 15, 2011 12:31 pm
by Ceprotec
hey sergey erro in: undeclared identifier: GetPageLastItemNo

why?

Posted: Sat Jan 15, 2011 12:52 pm
by Sergey Tkachenko
What version of ScaleRichView do you use?

Posted: Sat Jan 15, 2011 1:30 pm
by Ceprotec
Sergey, I do not know, because I did not bought .. have somewhere where I can see? :?

Posted: Sat Jan 15, 2011 1:41 pm
by Sergey Tkachenko
SRichViewEdit.Version property

Posted: Sat Jan 15, 2011 2:03 pm
by Ceprotec
v3.5

the function is GetPageStartItemNo SclRView but has not GetPageLastItemNo ..

Posted: Sat Jan 15, 2011 2:48 pm
by Sergey Tkachenko
Download a newer trial from http://www.trichview.com/download/