Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where class definitions can live

Status
Not open for further replies.

Olaf Doschke

Programmer
Oct 13, 2004
14,847
DE
Hello all,

just a short hint on the Newobject function. The documentation about it bugged me a bit, it says_
vfp help said:
NEWOBJECT(cClassName [, cModule [, cInApplication | 0 [, eParameter1, eParameter2, ...]]])

cModule
Specifies a .vcx file or Visual FoxPro program (.prg, .fxp, .mpr, .app, .exe, [highlight #FCE94F]and so on[/highlight]) containing the class or object specified with cClassName. The default is a .vcx file. If you specify a program file, you must include an extension.

What do you mean "and so on"?

The givens are quite broad possibilities and I think nobody really cares much, as you can always put a class into a prg or vcx and that's where they belong anyway. Some base classes can only be subclasesed in a PRG ('Session', for example).

What about another very valuable location of classes you can share with the users of your app? Something you can provide without updating the installation (well, aside from the fact that new classes usually also need new code to use them, but think about updates of existing classes).

I thought of trying a DBC as cModule, but that fails, And cInApplication is even just for specifying an EXE or APP that contains the VCX or PRG or other file cModule specifies.

Still, this brought me to a very simple way of providing a class in a DBC, that not necessarily is only meant to be used by the DBC stored procs. It might provide a feature for your DBC but also for other external extensions, just like a DBC is a natural place for remote views to actually use a remote database it could be the headquarter to other external and remote things that root in a VFP class definition. For example, a class using a REST API. In the end, you use this within the VFP EXE process and can also add it there in a VCX, but why not go other routes, too?

And here's the point, that may even be a disappointment and you already use this all the time, but it just occurred to me as not just a hack but a natural way to locate some things, especially data access related:

Code:
Procedure dbcObject(tcClass)
   Return CreateObject(m.tcClass)
Endproc

Yes, that's all folks. And to be very clear it doesn't add DBC as a possible class location for the NEWOBJECT function, but for VFP at all. Just a language extension made available by having a DBC open. And if you're normal in first spotting the quote and code sections of a post you may never even read all this anyway and still get it: If you put this into the stored procs of a DBC you can instance classes defined inside it also outside of the DBC. Obviously, that also needs class definitions in the DBC and it's limited to PRG classes (DEFINE CLASS) and it also should be class definitions relevant to being located there, ie for being used within the DBC, but it's not just limited to that.

Just think about how that enables switching between DBCs with other implementations of the same family of classes with the same names or other ways of making use of it. And it's in one central place that a LAN application makes use of. Even when you already migrated all your data to server backends and not use remote views, you'll still know how your application can easily let all users see a DBC in a file share. And now it can become a repository of a library of functionality.

A con is obviously that instancing a class reaches into the LAN, but the instance itself is just an integral part of the client process as any other class instance coming from a VCX or PRG compiled into the EXE.

And yes, there are other ways of just putting FXPa or PRGa or VCXes into a file share without a DBC, so a reason should perhaps be, that the classes are related to the DBC itself, ie classes the stored procs within the DBC use. They won't need the dbcObject function itself to make the class definition accessible, as you can always use CREATEOBJECT() to find classes defined in the current code context. But maybe it already helps to realize that you can actually make use of OOP within a DBC stored proc and write OOP style referential integrity or audit trail code, for example. The stored procs don't limit you to procedural programming style within DBC routines. And it might also make available data access objects like cursor adapters that, well, are up to date with the current DBC table structures, just to name one possible idea of a sensible usage of this contained in a DBC and not the updated version of your EXE.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf,
My suggestion is you construct a better content for that particular subject in the Helpfile and forward that to Francis Faure who is most willingly to update the Helpfile.
Bi,
Koen
 
You get this a bit backward. I didn't rant about the help being unclear or wrong here. I can thank that "and so on" for thinking about the option to make use of the stored procs in an OOP fashion. Because I'm closing in on a very fine transaction logging add on for DBCs. So actually thanks for that idea. It wasn't crucial to get there, but I picked the option to have a very well confined transaction logging also in terms of where the code for it goes.

Thank you for that remark and pointer anyway, Yes, that could be something to address in the help file. I'm still not sure what "and so one" could be apart from the already mentioned file types. The help as-is even already is a bit verbose, because fxp just is the compiled prg, not really a different option. MPR would be a strange place to put a class, but like stored procs or just the general PRG they are a simple text file containing possible procedure/function and class definitions besides code started from the top when you DO a prg or mpr.

I was mostly just posting a tip here, you see the thread type.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf,
I second your opion completely, yes the Help is not clear at all in this topic. Let us see what you propose to change here which would be a good job.
Bi,
Koen
 
Well, as you're so keen on me requesting that change, would you agree on this?

help correction said:
cModule
Specifies a .vcx file, Visual FoxPro program files [highlight #FCE94F](.prg/.fxp, .mpr, .app, .exe, and so on) or a compiled project (.app/.exe)[/highlight] containing the class or object specified with cClassName. The default is a .vcx file. If you specify a program file, you must include an extension [highlight #FCE94F].prg or .fxp[/highlight].

You could also leave in .mpr/.mpx and, in fact, you could add .dll, even for non-olepublic classes, but I really think it's very misleading and then what could be the "and so on" actually are .qpr/.qpx and .spr/.spx, too.

Actually also the possibility to have a class definition in a DBC is indirectly in there already, as the help also says where VFP looks when you don't specify cModule (and further parameters):
actual help said:
If cModule is omitted, ... Visual FoxPro searches for the class ... in the following order: [ul]
[li]Visual FoxPro base classes.[/li]
[li][highlight #FCE94F]Classes in the current program[/highlight].[/li]
[li]....[/li][/ul]

"Classes in the current program" cover the stored procedures of a DBC. When your code is in there, too, it can also see DEFINE CLASS within the .dbc. So the dbcObject() function I suggest in my first post could also use NEWOBJECT() function in its definition.

Likewise here's not the point to tell that, of course, .dll aside of .app/.exe would also work, as built by VFP, but actually mainly meant for OLE classes (olepublic) and for third party language usage of VFP. Also, the way to specify OLE classes (built by other languages into .dll or .ocx files) has its own spotlight in the final remarks with the 'Excel.Sheet' example. And then there is DECLARE, too, for DLLs containing functions like Windows API system DLLs.

I guess "and so on" meant further types of program files .qpr/.qpx and .spr/.spx, and maybe .dll, though I'd simply skip that for leading off the core intent of the VFP language to provide classes in .vcx libraries as first citizen class storage and .prg/.fxp for subclasses of base classes the visual designer doesn't cover.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf,
I believe this change is a very good thing for the helpfile.
Stay healthy,
Koen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top