Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to call a member function when property value changes during run time


This question is not answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Aug 22, 2016 10:01 AM Last Post By: Adrian Bors
Adrian Bors

Posts: 12
Registered: 3/25/13
How to call a member function when property value changes during run time  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 7:42 AM
Hi,

I am creating a new component (colour button) from TPaintBox:

class PACKAGE TClrBtn : public TPaintBox
{
private:
TColor bClr, moClr ;

void __fastcall PBoxUpdate(void);
protected:
public:
__fastcall TClrBtn(TComponent* Owner);
__published:
__property TColor BackColour = {read = bClr , write = bClr } ;
__property TColor HoverColour = {read = moClr , write = moClr } ;

} ;

How can I call PBoxUpdate() member function when the value of BackColour property changes during run time?

I would like to redraw TClrBtn Paint Box with HoverColour when mouse enters (onMouseEnter event) on this component.
Could you please tell me, How to implement events for newly created components?

Regards,

Goran Ekstrom

Posts: 149
Registered: 1/10/04
Re: How to call a member function when property value changes during run time
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 8:02 AM   in response to: Adrian Bors in response to: Adrian Bors
Adrian Bors wrote:
How can I call PBoxUpdate() member function when the value of BackColour property changes during run time?

Getters and Setters is what you need:

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Creating_properties_Index

See Direct access and Access methods.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How to call a member function when property value changes during run time [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 8:07 AM   in response to: Adrian Bors in response to: Adrian Bors
El 22/08/2016 a las 16:45, Adrian Bors escribió:
Hi,

I am creating a new component (colour button) from TPaintBox:

class PACKAGE TClrBtn : public TPaintBox
{
private:
TColor bClr, moClr ;


void __fastcall SetBackColor(TColor Value);

void __fastcall PBoxUpdate(void);
protected:
public:
__fastcall TClrBtn(TComponent* Owner);
__published:
__property TColor BackColour = {read = bClr , write = bClr } ;

__property TColor BackColour = {read = bClr , write = SetBackColor } ;

__property TColor HoverColour = {read = moClr , write = moClr } ;

} ;

How can I call PBoxUpdate() member function when the value of BackColour property changes during run time?


void __fastcall TClrBtn::SetBackColor(TColor Value)
{
if (bClr!= Value)
{
bClr= Value;
PBoxUpdate();
}
}
Adrian Bors

Posts: 12
Registered: 3/25/13
Re: How to call a member function when property value changes during run time  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 22, 2016 10:01 AM   in response to: Adrian Bors in response to: Adrian Bors
Thanks to both Goran Ekstrom and Antonio Estevez.

Thanks for the code Antonio Estevez. It is working fine.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02