override left property

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.
sorentopAsked:
Who is Participating?
 
geobulConnect With a Mentor Commented:
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
 
robert_marquardtCommented:
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
 
sorentopAuthor Commented:
did not help
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
robert_marquardtCommented:
Did you call "inherited Create(AOwner);" first?
0
 
sorentopAuthor Commented:
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
 
robert_marquardtCommented:
Try overriding Loaded also.
If that does not work i will have to learn component building.
0
 
sorentopAuthor Commented:
Like this...didn't work


protected
  procedure Loaded; override;

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


0
 
karouriCommented:
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
 
sorentopAuthor Commented:
nice
in the constructor isn't couldn't I just write inherited instead of inherited Create(AOwner)
0
 
sorentopAuthor Commented:
I have a follow up question if anybody is interrested.
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20164527
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.