Changing variables

General TRichView support forum. Please post your questions here
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Changing variables

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

Post by Sergey Tkachenko »

PageCount - SRichViewEdit.PageCount.
You can find where the page starts using SRichViewEdit.GetPageStartItemNo.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

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

Post by Sergey Tkachenko »

I can try to modify an example, but FillFields from which demo do you use?
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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 ...
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

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

Post by Sergey Tkachenko »

Sorry for delay, I'll post code tomorrow.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

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

Post 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.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

hey sergey erro in: undeclared identifier: GetPageLastItemNo

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

Post by Sergey Tkachenko »

What version of ScaleRichView do you use?
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

Sergey, I do not know, because I did not bought .. have somewhere where I can see? :?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

SRichViewEdit.Version property
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

v3.5

the function is GetPageStartItemNo SclRView but has not GetPageLastItemNo ..
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Download a newer trial from http://www.trichview.com/download/
Post Reply