Page 1 of 1

Insert text item

Posted: Mon Mar 16, 2009 9:11 pm
by Igor
Hi!
I try to create simple template editor. I load in RichView text like this:
Hello. My name #NAME. I am #AGE years old.

After load to RichView in text I must replace variables #NAME and #AGE to emply text items. Text will be protected, variables - not! How can i do this?

I tried to use example from help:

Code: Select all

 

procedure TForm1.Search(ARVData: TCustomRVData);
var
  I, N, R, C, StyleInd, ItemStyle: Integer;
  S: string;
  VName, AItemText: string;
  B: Boolean;
  Table: TRVTableItemInfo;
  RVEditData: TRVTableCellData;
begin
                           
  i := 0;
  repeat
    ItemStyle := ARVData.GetItemStyle(i);
    if ItemStyle >= 0 then // text item
    begin 
      AItemText := ARVData.GetItemText(I);
      N := Pos('#',AItemText); // if var exists 
      if N > 0 then
      begin
        B := ExctractVariable(AItemText,VName); // get var. name
        if B do
        begin
           
          if var is at the start text item then i insert empty before current item;

         if var is at the end text item then i add empty after current item;

         if var is in text item then i devide current item to two and insert empty text item between them.

          How can i do this?




        end;
     end;
     
     I := I + 1;
   until 
      I = ARVData.ItemCount;
end


Posted: Tue Mar 17, 2009 10:14 am
by Sergey Tkachenko
You can look in MarkSearch.pas from RichViewActions. This unit searches for substring and highlights all occurences. Highlighting means deleting this substring from a text item and inserting a new text item (of another text style) in place of it, so this task is very similar with yours.

Note that in the current version of TRichView documents having empty items in the middle of text are considered invalid, so I suggest to insert spaces instead, then trimming user input when necessary.

Posted: Tue Mar 17, 2009 3:33 pm
by Igor
Thank a lot, Sergey. I'll try.