How do you implement a Screen Resize event handler?
The obvious way is to have a timer that continuously looks for changes in _screen.height and _Screen.Width
There is a more elegant solution, though. And here's how:
This code now works - Sergey Berezniker
Warning This trick will not work in VFP8SP1 and later. Use
DEFINE CLASS Resizer AS Custom
oScreen = _Screen
WAIT window "Resizing" NOWAIT
Thanks Sergey for figuring out the correct syntax. - ?wgcs
What I can't figure out is why does
PROCEDURE oScreen.Resize work at all? Are there other instances in VFP where contained object events fire the
PARENT events? Though this works, I wonder if this is a feature or a bug.-- Steven Black
The reason that this trick works (my guess) is caused by the way VFP stores objects. Internally it seems to create a new name table for each object (hence the limit of 65,000 PEMs) where each entry refers to one PEM. Methods are treated like properties. Their value points to the location of the VFP code. The other issue is that classes are objects internally. For every class, VFP creates a master object which you can access with THIS in expressions you put into properties with "=". Each time an instance of a class is created, the master object is copied over the new empty object to initialize all properties.
What happens here is that during the assembling phase of the class object, the parser hits the "PROCEDURE oScreen.Resize" line after hitting oScreen. The validation routine verifies that oScreen is an intrinsic PEM. Assuming that it still works on the class object the parser goes ahead, loads the method code and writes the location into the method property "Resize". Unfortunately, in this case the target object was not a class object, but a live object.
With this trick you can override any method in any VFP object, not COM objects. However, since the trick depends on the class object generation, it only happens the first time you load the class.
-- Christof Wollenhaupt
See also: Screen Methods
Contributors: wgcs, Sergey Berezniker
Category VFP Events
( Topic last updated: 2012.08.22 08:17:14 PM )