Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OleControl with parameter in Init()
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Title:
OleControl with parameter in Init()
Miscellaneous
Thread ID:
00539127
Message ID:
00539127
Views:
52
When an oleControl class is defined in code, and you want to pass a parameter to the Init() method of the class, it appears that the oleClass property is required as the first parameter. Since an oleControl class must be instantiated on a form, you have to instantiate them with form.AddObject() or form.NewObject(). oleClass is documented as a parameter of the AddObject() method, but I didn't realize it would be passed as the first parameter to Init(). oleClass is not mentioned at all in the NewObject() documentation, but it is required as the first parameter as well. Passing an invalid value for oleClass results in an "Invalid Class String" error, which is how I figured this out in the first place. You can get away with passing nothing for oleClass, but if you do pass something, note that it will override the setting in the class definition. The moral of the story is that if you want to pass parameters to Init() in this scenario, you need to start with the second one. This does not apply to oleControls created visually. It looks like they are handled differently.

Has anyone run across this one before? I'm not sure if it is a bug, or more importantly, if I would want it fixed. It could certainly cause a problem if parameter positions were shifted in a future release. Sample code is below:
oForm = CreateObject("form")

* This causes error since "parm1" is an invalid value for oleClass
oForm.NewObject("oOutline","oleOutline",,,"parm1","parm2")

* This works ok
oForm.NewObject("oOutline","oleOutline",,,,"parm2")

* This works, but overrides oleClass property in class definition
oForm.NewObject("oOutline","oleOutline",,,"MSComctlLib.TreeCtrl.2","parm2")

Define Class oleOutline as oleControl

	oleClass = "msoutl.Outline"
	
	Procedure Init(lcParm1,lcParm2)
		If !empty(lcParm1)
			messagebox(lcParm1)
		Endif
		messagebox(lcparm2)
		messagebox(this.oleclass)
	Endproc
	
Enddefine
Next
Reply
Map
View

Click here to load this message in the networking platform