Hi Brian,
Thanks for your comments. A builder would be a good idea. I had some plans to generate object menu code from the .MNX file created by the VFP menu builder. I still think that this would be a good approach, but I haven't had the time to do it. As far as distributing the compiled code is concerned, I have no problem with that. Although I am having problems with the VFP 6 version.
A while ago I set about recompiling for VFP 6 and the code started crashing. Same stuff works fine in VFP 5. I had a brief msg exchange with Randy Brown at Microsoft who said that the problem was by design and that was that!
As object menus are once more being talked about, I would welcome input from anybody on this issue.
Here's the code example that I used to highlight the problem to Randy. The issue is that a reference to THIS.Parent is now not working in the Destroy of an object.
This works in VFP5 but not VFP6
*------------- Start BugDemo.Prg
*-- This mimics the creation of a hierarchy of menu objects
CLEAR
_SCREEN.AddObject("Menu", "MainDemo")
_SCREEN.Menu.AddObject("File", "SubDemo")
_SCREEN.Menu.AddObject("Edit", "SubDemo")
_SCREEN.Menu.AddObject("View", "SubDemo")
_SCREEN.Menu.AddObject("Tools", "SubDemo")
_SCREEN.Menu.AddObject("Help", "SubDemo")
_SCREEN.Menu.File.AddObject("Exit", "SubDemo")
_SCREEN.Menu.Edit.AddObject("Copy", "SubDemo")
_SCREEN.Menu.View.AddObject("Data", "SubDemo")
_SCREEN.Menu.Tools.AddObject("Test1", "SubDemo")
_SCREEN.Menu.Tools.AddObject("Test2", "SubDemo")
_SCREEN.Menu.Tools.AddObject("Add", "SubDemo")
_SCREEN.Menu.Tools.AddObject("Test3", "SubDemo")
_SCREEN.Menu.Help.AddObject("About", "SubDemo")
_SCREEN.Menu.Tools.Add.AddObject("Report", "SubDemo")
_SCREEN.Menu.Tools.Add.AddObject("Remove", "SubDemo")
_SCREEN.Menu.Tools.Add.Report.AddObject("Print", "SubDemo")
_SCREEN.Menu.Tools.Add.Report.AddObject("Preview", "SubDemo")
*-- Demonstrate the problem.
WAIT WINDOW "Press any key to crash me (VFP 6 only)"
_SCREEN.Menu.Tools.Add.Remove.Execute()
*-- If you just DO KillItems here, without using the EXECUTE method
*-- then all is OK
*-- DO KillItems
*-- If all is well, we'll get to this point
_SCREEN.RemoveObject("Menu")
? "Done It"
*-- Remove a couple of the menu items
PROCEDURE KillItems
_SCREEN.Menu.Tools.Add.RemoveObject("Report")
_SCREEN.Menu.Tools.Add.RemoveObject("Remove")
*-- Define Two classes.
DEFINE CLASS MainDemo AS CUSTOM
Children = 0
ENDDEF
DEFINE CLASS SubDemo AS CUSTOM
PROTECTED pCommand
Children = 0
*-- For the demo, all objects have the same command
pCommand = "DO KillItems"
PROCEDURE Execute
LOCAL lcCommand
lcCommand = THIS.pCommand
*-- Start debugging here!
&lcCommand
ENDPROC
PROCEDURE Init
THIS.Parent.Children = THIS.Parent.Children + 1
? "INIT " + THIS.Name
ENDPROC
PROCEDURE Destroy
THIS.Parent.Children = THIS.Parent.Children - 1
? "KILL " + THIS.Name
ENDPROC
ENDDEF
*--------- End BugDemo.Prg