Insert text item

General TRichView support forum. Please post your questions here
Post Reply
Igor
Posts: 2
Joined: Mon Mar 16, 2009 8:52 pm

Insert text item

Post 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

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

Post 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.
Igor
Posts: 2
Joined: Mon Mar 16, 2009 8:52 pm

Post by Igor »

Thank a lot, Sergey. I'll try.
Post Reply