Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse + OO Array
Posted: Fri Jun 06, 2014 04:48 PM
TDataSource is a good idea.
I think FWH would soon implement it. This can be the base class for Arrays, DBF, RecordSets and anything else we can imagine.
As far as XBrowse is concerned:
XBrowse is made to work with any user defined class PROVIDED that you define some methods and data.
There are basically two alternatives:
Alternative-1:
Define a
METHOD SetXBrowse( oBrw, aCols, lAutoSort, lAutoCols )
In this method you write code similar to that in SetODbf() method of xbrowse. You need to take care of all xbrowse settings.
Then you define XBROWSE the same way like you define XBROWSE for RDD/ADO.
If your class has method SetXBrowse, XBrowse will call your method instead of its own SetODbf.
You are responsible to do what SetoDbf does for TDataBase inside your method SetXBrowse()
Alternative-2
You define the following methods in your class, with the same functionality as in TDatabase:
Compulsory methods:
1) Bof()
2) Eof() // note: Set eof only when nAt > nLen
3) GoTop()
4) GoBottom()
5) RecNo()
6) GoTo( nRec )
7) KeyNo()
8 ) KeyGoTo( nKey )
9) KeyCount()
10) RecCount()
11) SetOrder( cColumnName ) --> Oldorder name
// This should exactly work like OrdSetFocus()
Most important method:
12) Skipper( n ) --> nSkipped
Compulosry DATA
Actually optional, but you can not use columns clause without this data. So consider it as compulsory:
DATA aStruct
aStruct should be an array similar to DbStruct(), with field name, type, len and dec. XBrowse uses this array to work with the column definitions in your class.
I presume you have implemented on error method so that :
obj:<colname> returns value of the column and
obj:<colname> := x sets the new value of to the colname
Optional but highly Desirable Methods:
1) Seek( cSeek, lSoftSeek, lWildSeek ) // if the method exists, XBrowse uses this for incremental seeks. XBrowse uses only 1st and 3rd parameters.
2) Delete()
3) OrdDescend( cOrder, <ignore>, lDescend ) // Works like OrdDescend() function
If you provide these methods in your class with appropriate functionality, you can use it with xbrowse like any other dbf/rdd/ado/tdolphin, etc.
@ r,c XBROWSE oBrw OF oWnd DATASOURCE oMySpecalObject COLUMNS cCol1, cCol2 ................... and same like other browses ......
XBrowse detects that you are using an Object. Then it decides that your object is not TDatabase, RecordSet, SqlQuery but something else.
Then XBrowse checks to see if your Object has method "SetXBrowse". If so, xbrowse simply calls your method SetXBrowse and hands over total responsibility to your method.
If not it checks if your object has the methods I stated above and if so goes ahead and constructs the browse using your methods.
If not it simply offers to browse your object as an unknown object ( Hope you know we can browse oDlg, oWnd, etc .. any object )
-------------
Having said this, let me add a few notes:
Hereafter no new methods like SetAdo, SetArray, etc will not be added to accommodate new classes. It is enough if the class is designed providing above methods and any such object can be xbrowsed just like any other rdd/ado, etc.
If we acquire a class from some source, which does not provide these methods, then our advice is to write a small wrapper class providing the above methods. Now the class is ready to be xbrowsed.
PS: I personally use my own classes TArray (like yours) and TAdoBase for recordsets for many years. I did not modify XBrowse for my classes. My classes use the above mechanism and my programs use the same syntax like other xbrowses for browing my classes.
Regards
G. N. Rao.
Hyderabad, India