Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A New Creation
Message
From
18/01/2003 00:48:15
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
18/01/2003 00:24:14
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Title:
Miscellaneous
Thread ID:
00743090
Message ID:
00743100
Views:
14
This message has been marked as the solution to the initial question of the thread.
>I have a habit of using code like this:
>
>
oMyObj = CreateObject("CoolClass")
>
>when I want to instantiate a class. However I have been seeing code snippets that are more like:
>
>
oMyObj = NewObject("CoolClass")
>
>When should I be using each?

The difference is in the second parameter of NewObject() - both function and method. The second parameter is the classlib (or .prg), so you don't have to Set Classlib To ... or Set Procedure To ... to have it available for Createobject(), you can explicitly say from which library you want the object to be created.

Both ways have their downsides - if you open all classlibs and procedure files at startup (as some frameworks do), you can go merrily with createobject() and never bother with the actual locations; this also means you'll have trouble locating the class when debugging. The other method requires you to know where your class is defined when you want to use it, and you don't have to open all classlibs and procedure files in advance, but then you have to know their names while writing, and if you move a class from one classlib to another, your code will break (while in the first case it won't).

There's also a weird thing about having all classlibs open - if you have a class of same name in several classlibs, and all of them are open, which one will get created is a matter of the order of opening the classlibs. I think it's "the last takes it all", but haven't used the other framework which worked that way for quite a while.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform