Board index » cppbuilder » E2247 'TControl::Text' is not accessable

E2247 'TControl::Text' is not accessable

When I try to access certain properties of a component using
ActiveControl, I receive a compiler error(E2247 'TControl::Text' is
not accessable). I'm assuming this is because certain properties are
private or protected. Is there a way around this? I'm trying to write
one event handler that will be called for many TEdits depending upon
which one has focus.

Example:
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
    try {
        ActiveControl->Text.ToInt();  //COMPILER ERROR
    }
    catch ( EConvertError& ) {
        Application->MessageBox(
           "Please enter an integer value!", "Error", MB_OK);
    }

Quote
}

Thanks
Brad Trotte
 

Re:E2247 'TControl::Text' is not accessable


You could castActiveControl to a TEdit first, but a better way would be to
cast use the Sender parameter of the event handler instead, as it poits to
the control that triggered the event:

void __fastcall TForm1::Edit1Change(TObject *Sender)
{
    try {
        // either this ...
        ((TEdit*)ActiveControl)->Text.ToInt();

        // or else this...
        TEdit *edit = dynamic_cast<TEdit*>(ActiveControl);
        if(edit)
            edit->Text.ToInt();
    }
    catch ( EConvertError& ) {
        Application->MessageBox(
            "Please enter an integer value!", "Error", MB_OK);
    }

Quote
}

Gambit

Quote
Brad Trotte <trot...@wpunj.edu> wrote in message

news:eqntosc1pen1be9u07iovun5ne9jcclmnf@4ax.com...
Quote
> When I try to access certain properties of a component using
> ActiveControl, I receive a compiler error(E2247 'TControl::Text' is
> not accessable). I'm assuming this is because certain properties are
> private or protected. Is there a way around this? I'm trying to write
> one event handler that will be called for many TEdits depending upon
> which one has focus.

Other Threads