Getting ItemText of all controls in document

General TRichView support forum. Please post your questions here
Post Reply
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

Getting ItemText of all controls in document

Post by hdassler »

Hello,

I'm trying to get ItemText for all controls in document.
While using GetItemText(ItemNo) it works, but not with using
GetCurrentItemText() in tables

Code: Select all

void __fastcall TForm1::ControlAction(TCustomRichView *Sender,
      TRVControlAction ControlAction, int ItemNo, TControl *&ctrl)
{
      if(ControlAction == rvcaAfterRVFLoad) {
           TRichViewEdit *rve = (TRichViewEdit *) Sender;
           ShowMessage(rve->GetCurrentItemText());
      }
}
OR

Code: Select all

             ...
              int  x = 0;
              while(x <  rve->ControlCount) {
                 rve->SelectControl(rve->Controls[x]);
                 ShowMessage(rve->GetCurrentItemText());
                 x++;
              }
              ...
how should I use function GetCurrentItemText to get the text?

(Need it after editing XML and use <control >[ItemText]</control> as
text in a TMemo)

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

Post by Sergey Tkachenko »

Using rve->Controls[] is not a good method for controls enumeration.
Cell inplace editor is also included there, but controls in this editor are not included.

The changed example is below.
It uses EnumItems() method. This method calls the specified procedure for each item in document.

Code: Select all

void __fastcall TForm1::EnumItemsProc(TCustomRVData* RVData, 
  int ItemNo, int& UserData1, const AnsiString UserData2, 
  bool& ContinueEnum) 
{ 
  ContinueEnum = true; 
  if (RVData->GetItemStyle(ItemNo)==rvsComponent)
  {
    ShowMessage(RVData->GetItemText(ItemNo)); 
    UserData1++;
  }
} 

void __fastcall TForm1::Button1Click(TObject *Sender) 
{ 
  int v=0; 
  RichViewEdit1->RVData->EnumItems(EnumItemsProc, v, ""); 
  ShowMessage("Control count:"+IntToStr(v)); 
}
Sergey Tkachenko
Site Admin
Posts: 17604
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for reading text at the moment of RVF loading...
rve->GetCurrentItemText() cannot be used there.
This method returns text of the item at the position of caret.
When RVF is being loaded, caret position is undefined (document is not formatted yet). Calling rve->GetCurrentItemText() at that time may cause exception. In any case, the result is undefined.

Unfortunately, there is no way to read the control text in this event, because this event does not have RVData parameter (this method was introduced before introducing "RVData" concept)
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

Post by hdassler »

Hi Sergey,

thx for fast answering.
But I've got also problems with it.

While not using tables the ItemText could read and is right.
While using tables the ItemText could also read but is empty.

But with GetControlInfo it works.

Many thx.

Code: Select all

void __fastcall TForm1::EnumItemsProc(TCustomRVData* RVData,
  int ItemNo, int& UserData1, const AnsiString UserData2,
  bool& ContinueEnum)
{
  ContinueEnum = true;
  AnsiString Text1;
  TControl *ctrl;
  TRVVAlign VAlign;
  int ATag;

  if (RVData->GetItemStyle(ItemNo)==rvsComponent)
  {
    RVData->GetControlInfo(ItemNo, Text1, ctrl, VAlign, ATag);
    ShowMessage(Text1);
    UserData1++;
  }
}
Sergey Tkachenko
Site Admin
Posts: 17604
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

My initial post had a mistake with calling GetItemText not for RVData, but for the editor.
I fixed it immediately, but probably you used the wrong version.
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

Post by hdassler »

Oh, you're right. it works, too.
I testet it with the Editor, not RVData.
Post Reply