Page 1 of 1

Getting ItemText of all controls in document

Posted: Fri Jun 09, 2006 8:35 am
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

Posted: Fri Jun 09, 2006 2:57 pm
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)); 
}

Posted: Fri Jun 09, 2006 3:07 pm
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)

Posted: Sat Jun 10, 2006 7:45 am
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++;
  }
}

Posted: Sat Jun 10, 2006 10:26 am
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.

Posted: Sat Jun 10, 2006 10:36 am
by hdassler
Oh, you're right. it works, too.
I testet it with the Editor, not RVData.