Solved

override left property

Posted on 2001-08-07
10
241 Views
Last Modified: 2010-04-06
Hi I'm creating a TGroupbox component and want to get a notification when the left value is changed so.

private
  FLeft: Integer;
  procedure SetLeft(const Value: Integer);
published
  property Left: Integer read FLeft write SetLeft;

procedure TCheckGroupBox.SetLeft(const Value: Integer);
begin
  FLeft := Value;
  inherited Left := Value;

  //Do my stuff
end;

When I place the component on the form the left value is set to 0, how do I set it to the inherited value?
Should I perhaps use a different way than making the left property, the way I do now.
0
Comment
Question by:sorentop
10 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6358921
Such properties are usually set to a generic value in the constructor.
Try overriding the constructor and do a
 FLeft := inherited Left;
This should sync your initialization.
0
 

Author Comment

by:sorentop
ID: 6358979
did not help
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6359019
Did you call "inherited Create(AOwner);" first?
0
 

Author Comment

by:sorentop
ID: 6359036
I think so, it looks like this

public
constructor Create(AOwner: TComponent); override;

constructor TCheckGroupBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLeft := inherited Left;
end;
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6359138
Try overriding Loaded also.
If that does not work i will have to learn component building.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:sorentop
ID: 6359151
Like this...didn't work


protected
  procedure Loaded; override;

procedure TCheckGroupBox.Loaded;
begin
  inherited;
  FLeft := inherited Left;
end;


0
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 6359178
Hi,
As you already have FLeft field and Left property defined in the TControl, you just need to override SetLeft procedure:

  private
   procedure SetLeft(Value: Integer);
  public
   constructor Create(AOwner: TComponent); override;
  published
   property Left write SetLeft;
  end;

constructor TCheckGroupBox.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
end;

procedure TCheckGroupBox.SetLeft(Value: Integer);
begin
  inherited Left := Value;
  // do your stuff here
end;

Regards, Geo
0
 
LVL 3

Expert Comment

by:karouri
ID: 6359332
Listening, and interested in results..
>Try overriding Loaded also.
>If that does not work i will have to learn component building.
I hope that does help. I tried to make a TLine component with special features, and the very thing I needed was to 'overload' the Left and Top properties. e.g. an event OnLeftOrTopChanged or overriding SetLeft and SetTop.
The result I had was that there is no way to do it, for some reason Borland wasn't making such a choice available.

sorentop's needs may be satisfied in another way than 'overriding' Left, but I am offering 250 points if this problem is solved satisfactorily..
0
 

Author Comment

by:sorentop
ID: 6359337
nice
in the constructor isn't couldn't I just write inherited instead of inherited Create(AOwner)
0
 

Author Comment

by:sorentop
ID: 6359399
I have a follow up question if anybody is interrested.
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20164527
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now