How to get the ItemNumber of an existing String?

General TRichView support forum. Please post your questions here
Post Reply
RichEnjoyer
Posts: 14
Joined: Fri Jan 20, 2006 11:05 am
Location: Germany

How to get the ItemNumber of an existing String?

Post by RichEnjoyer »

Hello,

how can i get the number of an existig Item?

I have...

RichView1.AddNL('MyFirstLine',0,0);
RichView1.Add('example',1);
RichView1.Format;

now i search the ItemNumber of "MyFirstLine" ?

Is it possible to get the ItemNumber?

best regrads, Frank
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The simplest way is to store item index at the moment of document generation:

Code: Select all

MyFirstLineItemNo := RichView1.ItemCount;
RichView1.AddNL('MyFirstLine',0,0); 
RichView1.Add('example',1); 
RichView1.Format; 
or you can search for it:

Code: Select all

MyFirstLineItemNo := -1;
for i := 0 to RichView1.ItemCount-1 do
  if RichView1.GetItemTextA(i)='MyFirstLine' then begin
    MyFirstLineItemNo := i;
    break;
  end;
Of course, this code returns the proper value only if there is no another text item with 'MyFirstLine' text.
RichEnjoyer
Posts: 14
Joined: Fri Jan 20, 2006 11:05 am
Location: Germany

Post by RichEnjoyer »

Ok thanks,

it works fine! :-)
i make the edit with...

rvAdd.SetItemText(intP+POS_MSGCNT,IntToStr(intMsgCnt));

is work good.
How change the ParaStyle?

I want switsh to ParaStyle No 2 when the intMsgCnt>5.

It is posibble?


best regrads, Frank
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

rvAdd.GetItem(i).ParaNo := new_value.

But very important: all items in the same paragraph must have the same value of ParaNo, otherwise the document will be invalid.
(the i-th item starts a new paragraph, if rvAdd.IsParaStart(i)=True)
Post Reply