Board index » cppbuilder » Getting Property-Name in Read-/Write-Methods

Getting Property-Name in Read-/Write-Methods

Hello,

usually you have to define a different method for every read-/write-access
from/to your properties.

In my case, I want to centralize some modifications in one method, but must
determine which property is accessed actually.
Therefore I must know the name of the property which "triggered" the
Read-/Write-Method.

Is there any way to get the property-name of these methods?
I'm working with C++Builder 5.

Any hints?

Kind regards from Germany,
Udo Weik

 

Re:Getting Property-Name in Read-/Write-Methods


Quote
"Udo Weik" <WeikEng...@aol.com> wrote in message

news:3CA6CB48.CD6691A8@aol.com...

Quote
> In my case, I want to centralize some modifications in one
> method, but must determine which property is accessed actually.

You can use an index attribute for that.  You can have each property call
the same method, passing it a different index value that you can test for,
ie:

    __property int MyProp = {read=GetMyProp, write=SetMyProp, index=0};
    __property int MyProp2 = {read=GetMyProp, write=SetMyProp, index=1};
    __property int MyProp3 = {read=GetMyProp, write=SetMyProp, index=2};

    int __fastcall TMyComp::GetMyProp(int Index)
    {
        switch(Index)
        {
            ...
        }
    }

    void __fastcall TMyComp::GetMyProp(int Index, int Value)
    {
        switch(Index)
        {
            ...
        }
    }

Quote
> Is there any way to get the property-name of these methods?

Not the name itself, no.

Gambit

Re:Getting Property-Name in Read-/Write-Methods


Hello Gambit,

thanxs again. That's exactly what I have looked for.
Meanwhile I have read a lot, but not found any hint about
that topic. Are there any other secrets like this??

Quote
"Remy Lebeau [TeamB]" wrote:

> "Udo Weik" <WeikEng...@aol.com> wrote in message
> news:3CA6CB48.CD6691A8@aol.com...

> > In my case, I want to centralize some modifications in one
> > method, but must determine which property is accessed actually.

> You can use an index attribute for that.  You can have each property call
> the same method, passing it a different index value that you can test for,
> ie:

>     __property int MyProp = {read=GetMyProp, write=SetMyProp, index=0};
>     __property int MyProp2 = {read=GetMyProp, write=SetMyProp, index=1};
>     __property int MyProp3 = {read=GetMyProp, write=SetMyProp, index=2};

>     int __fastcall TMyComp::GetMyProp(int Index)
>     {
>         switch(Index)
>         {
>             ...
>         }
>     }

>     void __fastcall TMyComp::GetMyProp(int Index, int Value)
>     {
>         switch(Index)
>         {
>             ...
>         }
>     }

> > Is there any way to get the property-name of these methods?

> Not the name itself, no.

> Gambit

Other Threads