Solved

override left property

Posted on 2001-08-07
10
235 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

23 Experts available now in Live!

Get 1:1 Help Now