Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code Adds Wrong Class
Message
From
14/02/2008 11:10:51
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01291993
Message ID:
01292604
Views:
24
>>>>>I have a section of code that adds a button to a form. The problem is that there are
>>>>>multiple command buttons with the same name in various class libraries all over the application.
>>>>>
>>>>>The name of the class and the VCX it's in are stored on the form as properties:
>>>>>
>>>>>
>>>>>cLibrary = GETWORDNUM(ThisForm.button, 2, ',')
>>>>>cClass = GETWORDNUM(ThisForm.button, 1, ',')
>>>>>
>>>>>SET CLASSLIB TO (cLibrary) ADDITIVE
>>>>>
>>>>>ThisForm.AddObject(cClass, cLibrary)
>>>>>
>>>>>
>>>>>The problem is that because there are many copies of this button with the same name,
>>>>>just in different VCS's, the wrong class is added.
>>>>>
>>>>>Anyone know how to fix this?
>>>>
>>>>Actually this explains one of the reasons for X8SETCLS in VMP. :)
>>>>
>>>>Further if you have a single uniquely-named classes (and UDFs) you could not possibly have the situation you describe. Using PRGs with multiple UDFs allows for two UDFs to have the same name in different PRGs. Same thing with classes.
>>>
>>>Not necessarily true. Try this:
>>>
>>>
>>>CLEAR
>>>
>>>SET PROCEDURE TO
>>>SET PROCEDURE TO test1 additive
>>>SET PROCEDURE TO test2 additive
>>>=a()
>>>** Prints 'test1_aaaaaaaaaa'
>>>
>>>SET PROCEDURE TO
>>>SET PROCEDURE TO test2 additive
>>>SET PROCEDURE TO test1 additive
>>>=a()
>>>** Prints 'test2_bbbbbbbbbb'
>>>
>>>RETURN
>>>
>>>
>>>** PROGRAM FILE Test 1
>>>FUNCTION a()
>>>? 'test1_aaaaaaaaaa'
>>>ENDFUNC
>>>
>>>
>>>
>>>** PROGRAM FILE Test 2
>>>FUNCTION a()
>>>? 'test2_bbbbbbbbbb'
>>>ENDFUNC
>>>
>>>
>>>
>>>VFP finds the function in the order of the SET PROCEDURE commands. This is why I'm of the
>>>mindset that when you subclass something, call it a different name. And incidentally, I
>>>haven't used a procedure file since the days of 2.5, again, for this very reason. Too confusing.
>>
>>
>>You seem to have misunderstood me. I argue against ever allowing two procedures to have UDFs with the same name. Every UDF should be a PRG and no PRG should contain more than one UDF. Same with classes.
>
>OK, that I agree with. Sorry for the confusion.

Thanks!

There are a bunch of utility UDFs in VMP. I really like having these little UDFs provided they are named well. x2IsArray("somearray") is easier to understand than TYPE(ALEN("somearray"))="U". x2IsArray was donated to the general community by Russ Swall of VisionPace at my request for a FoxPro Advisor article I wrote on deleting a column from an array.

The x is supposed to reduce the chances of VFP someday having a matching IsArray function and the 2 indicates it will work as far back as FoxPro 2. :)

Hope that helps.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform