Solved

override left property

Posted on 2001-08-07
10
248 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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