Link to home
Start Free TrialLog in
Avatar of karouri
karouri

asked on

Overriding Left property..

In the question
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20164439
The problem of being notified when the left property is changed is raised. In particular, when placing the component in the form, I would like to have an event happen or an overriden Setleft procedure. I hope experts will try to answer that question..
Avatar of kretzschmar
kretzschmar
Flag of Germany image

listening . . .
Avatar of fva
fva

If you take a look at the VCL code you will notice lots of references to the Left property of all kinds of derivatives to TControl/TWinControl and that means you are not safe by just overriding SetLeft without making it virtual in the first place (in TControl).
Since the design of VCL does not allow for overriding properly the SetLeft (as a virtual method) I guess you're stuck. The quick hack would be to take the VCL source, change the definition of SetLeft in TControl to be a protected virtual method and then derive it to your pleasure. Of course, it has the drawback of a fully "custom" VCL which might cause you all kind of other problems and it might be a little tricky to get it compiled.

F.
ASKER CERTIFIED SOLUTION
Avatar of fva
fva

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you think any of the above is worth and you need further details, please say so.

F.
Avatar of karouri

ASKER

Actually both of your suggestions are sensible.
I have tested SetBounds overriding and it works, so I give you the points, though it is much more probable that I will capture the message in my work.
I have refrained from using SetBounds in the past because it does not allow you to modify Left or Top, while OnConstrainedResize is not conerned with Left and Top to modify them. The amazing thing is all you need is to pass your own values to inherited SetBounds..Sometimes one just,umm, oversee things;)
* Just to know, Can one modify the values of the WINDOWPOS record passed in the message to change Left or Top?

btw, I increased the points a little because it was very important to me and, well I have some points to spare
Thanks.

You should use WM_WINDOWPOSCHANGING to adjust the values. By the time WM_WINDOWPOSCHANGED comes in I think it would be too late to require a change.

F.