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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proper Base Class

Status
Not open for further replies.

DEDMOD

Programmer
Feb 1, 2001
721
US
I'm getting ready to create a rather major-league class having a ton of properties and methods and want to know what's best to use as the baseclass. I don't necessarily want it visible. But I do want it to be able to deal with several tables and or views and change them out as required. And I want to be able to add more than one instance of the object to a given form. Since I'm going to add them to forms I can't use forms, as I understand it. And I suppose I need private data sessions. I'd also like it to be web accessable if possible. What can I use, or am I asking too much?

Dave Dardinger
 
HI Dave,

I have created my own class and I am happy I did that way, since the whole behaviour of the project is well under my control and to my liking.

The 1st thing is n-tier thinking...
SO create a base class for every probable VFP class you will be using. That is the 1st thing, though you may never modify these base class. The [point is that incase you want a intermediary, you can always introduce that. Example..
myBaseClass
myBaseForm && of VFPs BaseForm class
myBaseForm1
myBaseFormMaster
myBaseFormData
May be Form Master has a navigationClass added to that and some basic functions like... checkMaster() or whatever functions and related properties. So when you need to create a form for a master.. say customer master... you shall be able to subclass myBaseFormMaster, add the AcMas Table to its DE, draw the fields into the form, set few properties.. such as the report form name, alias name, view name or whatever and the form shall be ready.

Now you want to add a helpclass, tooltip class, you can go back and add them to myBaseForm1 or myBaseForm Class, and there it will get implemented everywhere.

If you need a intermediary form.. you can introduce..
myBaseForm0 and redefine myBaseForm1 to be based on this.
So you dont have to redefine all forms etc.
SO the reason, to have a free spacing of classes (as I call it) and not use the Base Classes directly. Some one could argue, that I can still redefine my BaseForm as based on Form1.. But I keep up a naming convention..1,2,3 and 10, 11 as probable levels to think of them in ease on a later date, if need arise to introduce something.

Just some of my thoughts... If that helps you.. :)

Just a coincidence, I was thinking about my own textbox class, where I want the mouse to get a positioning without a click at the place where I key in something. If you think about it, may be this can be raised in the forum where others can contribute also on this. The point is.. when ever a mouse click is made on a text box, the cursor is positioned there. Same way, I want the mouse to get positioned wherever the cursor is placed. But I dont want the mouse to do a click when that is done. The result is .. a mouse over event will take place.. the tool tip will get activated.. and can indirectly provide a help on that. I have a version of my own ToolTip, which provides the help without removing the display.. so long the mouse is over the object. This type of functionals can be added, on a later date, if we use our own classes derived from base classes.

Best of luck.. Dave :) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Yes, I know about creating my own subclasses from the base classes. I have them all in my libded class library. And actually I have added some things to my ddedform class recently and it was nice not to have to do it to all the forms in my projects separately.

But my problem is which of these subclasses to use to create my new class from. I know some people who like to use separaters for non-visual classes, but they don't have private data sessions. I think someone here suggested using toolbars and I think I'll start with that and see what happens unless someone else has a better suggestion.
Dave Dardinger
 
I find I still can't add a toolbar to a form, just a formset. So what are the disadvantages of using a formset, if any? Other than having another level of hierarchy to work through when addressing objects?

Dave Dardinger
 
Dave

I find I still can't add a toolbar to a form, just a formset.

Why is important to you to add a toolbar to a form?

One of the advantages of toolbars is that they essentially belong to the application and are therefore completely independant of form or formset.

I would see attaching the attachment of a toolbar to form/formset as being negative rather than positive.

As far as the advantages of formsets are concerned, you would need to be advised of those by someone who uses them on a regular basis, Weedz of this forum being the only person I know.

IMHO, they are now a historical irrelevance, and I personally would not try to include them what you are now building for the future.

Chris :)
 
Well, I'm trying to create an object which will interact with databases / tables, but not, if possible, rely on a form's data environment. I think I want something with a private data session, so I don't have to worry about naming problems and the like if I have more than one of these objects open at the same time. As I understand it this limits my choices to forms, form sets and toolbars. But I'm really intending to make use of the visual atributes of the object, so it seemed to me that a toolbar was the best thing to use. And this requires using a formset as I understand it.

If you have a better idea, or think I'm all wet, say so. That's why I posted here in the first place. I suppose I can try to be more clear about what I have in mind.

I'm trying to encapsulate a way to deal with certain data sets. In particular the main data set will consist of a tree of entities; i.e. each 'node' will 0 or more nodes branching off it, but there will be no loops, etc. And each node may have additional information stored in a separate table with reference back to what node it's associated with. Both the nodes and the associated material come in certain 'types' the definition of which are stored in additional tables and finally there's a table of individual who may 'own' or modify given nodes. Finally I have a table such as has been discussed here a number of times, which stores the current record number for each table, allowing multiple users to work on the tables without interfering with each other.

Now I want to have the ability to return subsets of one of these trees or an ancestry of a given node or an analysis of the tree, etc. I think I want to have all this capability for handling the tree in one object, allowing the developer or even the user to call up multiple trees and combine, compare, slice and dice, etc. without having to make the programming too complex.

I'd also like to have capability to port the information generated by calling a particular method to several different sorts of clients including usual forms, remote programs using something akin to ODBC, to web browsers, perhaps even reports and files.

Suggestions other than what I've already proposed gratefully accepted.

Dave Dardinger

 
Dave

Thanks for the detailed explanation.

And this requires using a formset as I understand it.

Unless I misunderstand your objectives, that is a misconception.

A toolbar should be able to interact with other objects through object references and does not need to be attached to any object.

You would be simulating a formset if you initialised a toolbar(s) by passing parameter(s) to a form.

Equally you would be able to release the toolbar(s) when you close the form.

So you could develop the form/toolbar to be interdependant or not as you choose.

I sympathise with your concern to get the structure right from the onset - backtracking later could be a real pain.

Chris :)


 
Chris,

Somehow I feel I haven't communicated totally with you. I'm not particularly worried at this point about how to shut things down. I'll figure it out or come running here with questions. What I want to know is how to deal with what I think are going to be data access problems, particularly when more than one person is working on a project and when one person is using more than one tree at the same time.

But I agee that I don't need to worry about if my object is attached to a form or not. Indeed it'd be just as easy not to have it attached. But I guess I've been confused that I've tried adding my toolbar based class to forms and that always brings up a box telling me I need a formset to do that.

Probably once I've got my class working totally, it could be added via code on its own, but while working on it, I just went with the flow, so to speak, and did what the system suggested to create a test bed.

Dave Dardinger
 
Have you looked at the Session class? It was introduced with VFP6sp3.

It allows you to have a private data session without having a form or report. The only problem is it's not a Visual class. You have to create it via a PRG. This also means you will not be able to add it to a Form at design time unless you use another visual class (such as Custom) as a "wrapper" for your Session class. You CAN of course add it to a form at run time.

If you are wanting to achieve a "tree" scenario, I would suggest using the Custom class "wrapper" scenario because its "AddObject" method would come in handy.

Sample showing Session object:
Code:
** Create 2 Test forms
PUBLIC oForm1, oForm2
oForm1=CREATEOBJECT("MyForm")
oForm1.Caption = "Form 1"
oForm1.Visible = .T.
oForm1.Top = oForm1.Top-20
oForm1.Left = oForm1.Left-20

oForm2=CREATEOBJECT("MyForm")
oForm2.Caption = "Form 2"
oForm2.Visible = .T.

***********************************************************
DEFINE CLASS MyForm AS Form

Width = 200
Height = 300
AutoCenter = .T.
** These properties will hold the custom objects
oMySession1 = NULL
oMySession2 = NULL

ADD OBJECT cmdLocal AS CommandButton WITH ;
	Caption = "Local DataSession...", ;
	Top=20, Left=20, Width=150, Height=25
ADD OBJECT cmdSession1 AS CommandButton WITH ;
	Caption = "Custom DataSession 1...", ;
	Top=60, Left=20, Width=150, Height=25
ADD OBJECT cmdSession2 AS CommandButton WITH ;
	Caption = "Custom DataSession 2...", ;
	Top=100, Left=20, Width=150, Height=25
ADD OBJECT cmdClose AS CommandButton WITH ;
	Caption = "Close", ;
	Top=180, Left=20, Width=150, Height=25

FUNCTION Init
	** Add custom objects to form
	This.oMySession1 = CREATEOBJECT("MySession")
	This.oMySession2 = CREATEOBJECT("MySession")

FUNCTION cmdLocal.Click()
	MESSAGEBOX("Local DataSession: "+STR(SET("Datasession")))

FUNCTION cmdSession1.Click()
	ThisForm.oMySession1.ShowSession()

FUNCTION cmdSession2.Click()
	ThisForm.oMySession2.ShowSession()

FUNCTION cmdClose.Click()
	ThisForm.Release()

ENDDEFINE


***********************************************************
DEFINE CLASS MySession AS Session 

FUNCTION ShowSession
	MESSAGEBOX("Custom DataSession: "+STR(SET("Datasession")))

ENDDEFINE
 
Hi Dave,

I have used BoDurban's suggestion and I have created objects based on the Custom class. I have created a custom property called oDataSession to receive the session object. I have put the following code in the Init method:

This.oDataSession = CREATEOBJECT("Session") && you may want to subclass here....

Et voilà: you have a non-visual object with a data session. There is a caveat: Before opening your tables or views and before accessing them afterwards, you will need to issue a SET DATASESSION TO this.oDataSession.DataSessionID And a SET DATASESSION TO 1 when returning. A small price to pay for the convenience of a non-visual business object!

Thanks for your precious help!

Jean

 
Thanks guys. I am going to explore this data session object. I would have done it earlier, but a) wanted input from my local users group which met last night b) I couldn't find it because c) when I moved my base of operations to my new computer and installed Visual Studio 6.0 I didn't install the service pack (3) which came with it. This last I've now remedied and my feedback on session objects last night was positive so I'm off to try it out.

Dave Dardinger
 
Bo,

Too cool! Other than having to remove a couple of line breaks caused by posting it here, it worked first time. Now comes the fun of adding a bunch of properties and methods and tons of code!

Dave Dardinger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top