Page 1 of 1

Need help with inserting controls

Posted: Thu Feb 23, 2006 8:49 am
by IGDark
Hello,
I need to insert some components inside TRichViewEdit (TLabel & TProgressBar). I use AddControlEx function for this purpose. However, I also need to have an access to these components. Ex. I need to change a caption of one of the labels inside.
Could somebody plz give me an example of how I can find my TLabel and TProgressBar inside RichEdit, and change their properties?
The perfect case would be if you tell me how I can find the components by their names.

P.S. I tried to use FindChildControl() but it works ONLY with progress bars, but not with labels.

Thanks,
Alex.

Posted: Thu Feb 23, 2006 7:21 pm
by Pieter E.
Dear Alex,

You could add the following source in the OnSelect event of your TRichViewEdit (C++) to retreive information from a component:

Code: Select all

if(rve->CurItemNo < 0) return;
if(rve->CurItemStyle == rvsComponent)
  {
    AnsiString aName;
    TControl *aCtrl;
    TRVVAlign AVAlign;
    int iTag;
    int iIndex;
    rve->GetCurrentControlInfo(aName, aCtrl, AVAlign, iTag);
    if(aCtrl->InheritsFrom(__classid(TLabel)))
      {
         ShowMessage(((TLabel *)aCtrl)->Caption);
      }
  }
To replace the caption of a TLabel:

Code: Select all

if(rve->CurItemStyle == rvsComponent)
  {
    AnsiString aName;
    TControl *aCtrl;
    TRVVAlign AVAlign;
    int iTag;
    int iIndex;
    rve->GetCurrentControlInfo(aName, aCtrl, AVAlign, iTag);
    if(aCtrl->InheritsFrom(__classid(TLabel)))
      {
         ((TLabel *)aCtrl)->Caption = "Hello World";
         rve->SetCurrentControlInfo(aName, AVAlign, iTag);
         rve->Format();
         rve->SelectControl(aCtrl);
      }
  }

Posted: Fri Feb 24, 2006 3:16 am
by IGDark
Thanks, that does help!