Accessing and updating text in tables

General TRichView support forum. Please post your questions here
Post Reply
mobipro
Posts: 4
Joined: Fri Jan 06, 2006 4:34 pm

Accessing and updating text in tables

Post by mobipro »

Hi there, great component however I think I have hit a limitation regarding tables.

How can I access and update text in tables without recursion. Is there a direct way to do this.

Thanks in advance for the reply
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I can make an example, if you explain what you want to implement with more details.
mobipro
Posts: 4
Joined: Fri Jan 06, 2006 4:34 pm

Accessing and updating text in tables

Post by mobipro »

Hi again, thanks for the reply

Ok, I'm tring to replace field definitions in a table with the actual data. So I have say a 2x2 table with

|Date of birth |#{Field Name 1}|
|Age |#{Field Name 2}|

I need to replace it with

|Date of birth |25/05/1970|
|Age |35 |

I have a parser that handles various types of field definitions but it was not designed with recursion in mind.

So the question real is how to create the output table from the input table without accessing the tables recursively from my parser.

Below is a code snippet

Code: Select all

  for x := 0 to RichViewEdit1.ItemCount -1 do begin
    s := RichViewEdit1.GetItemTextA(x);
    s := StringReplace(s, '}#{', '} #{', [rfReplaceAll, rfIgnoreCase]);
    s := Trim(s);
    if Copy(Trim(s), 1, 3) = '#{*' then begin
      while Pos('*', S) > 0 do
        Delete(S, Pos('*', S), 1);
      while Pos('{', S) > 0 do
        Delete(S, Pos('{', S), 1);
      while Pos('}', S) > 0 do
        Delete(S, Pos('}', S), 1);
      while Pos('#', S) > 0 do
        Delete(S, Pos('#', S), 1);
      nf := FieldNameStrXX(Trim(s));   // FIELD NAME TO STRING
      tagid := Ord(nf);                         // FIELD ID
      GetFieldValue(t, tagid, Trim(s));   // FIELD VALUE TO STRING -> S
      itm := RichViewEdit1.GetItem(x); // RICHVIEW ITEM
      itm.StyleNo := TEXTSTYLE_FIELD;
      List.Text := t;
      for ii := 0 to List.Count -1 do
        RichViewEdit1.SetItemTextW(x, List[ii]); // SET STRING TO ITEM
      if List.Count -1 = 0 then
        RichViewEdit1.SetItemTextW(x, '');
      RichViewEdit1.SetItemTextW(x, t)
    end else if Copy(Trim(s), 1, 2) = '{*' then begin
      while Pos('*', S) > 0 do
        Delete(S, Pos('*', S), 1);
      while Pos('{', S) > 0 do
        Delete(S, Pos('{', S), 1);
      while Pos('}', S) > 0 do
        Delete(S, Pos('}', S), 1);
      nf := FieldNameStrXX(s);
      tagid := Ord(nf);
      GetFieldValue(t, tagid, s);
      itm := RichViewEdit1.GetItem(x);
      itm.StyleNo := TEXTSTYLE_FIELD;
      List.Text := t;
      for ii := 0 to List.Count -1 do
        RichViewEdit1.SetItemTextW(x, List[ii]);
      if List.Count -1 = 0 then
        RichViewEdit1.SetItemTextW(x, '');
      RichViewEdit1.SetItemTextW(x, t)
    end else if Copy(s, 1, 2) = '#{' then begin
 
Again thanks in advance
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Modification is rarher simple: instead of using RichView object for accessing items, use RVData object. It has the same methods and properties (ItemCount, GetItemText, SetItemText, etc.). And this procedure must be called not only for the main document, but for each table cells.
There are many examples for this. All mail merge demos support tables:
http://www.trichview.com/forums/viewtopic.php?t=8
Post Reply