xBrowse + OO Array

xBrowse + OO Array

Postby Marcelo Via Giglio » Mon Jun 02, 2014 9:22 pm

Hello,

I have a class for manipulate Arrays like TdataBase, there are method like skip, bof, fieldget fieldname, recno, etc

My question is how can I use xBrowse for navigate in the array like a datasource, I want to define columns with field names not by column number or array position number

With xBrowse is possible to do this?

regards

Marcelo
Marcelo Via Giglio
 
Posts: 1050
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: xBrowse + OO Array

Postby James Bott » Tue Jun 03, 2014 2:29 pm

Marcelo,

I wrote a similar class for arrays some time ago and was also hoping to use it with browses, etc. However, I found that xbrowse can't handle it because it has been modified to handle arrays as arrays. If I remember correctly the issue is that array class doesn't have an alias and if xbrowse doesn't find an alias then it assumes the datasource is a database.

Personally, I think it would have been better to use classes for arrays and other data sources rather than attempt to build all the special code into the browse. This would be more in keeping with OOP design principles, and it would have made it easier to setup browses since all the setups would have been the same. However, it is too late for that now.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xBrowse + OO Array

Postby Antonio Linares » Wed Jun 04, 2014 7:52 am

Marcelo,

Have you tried to inherit your class to manage arrays from TDataBase and adjust whatever is needed ? (not sure if it will be too messy)

CLASS TArrayData FROM TDataBase

this way the browse will think that its using a TDataBase object.

I agree with James, a generic Class TDataSource would have been the best solution, and then inherit from it to implement TDbfSource, TArraySource, etc.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xBrowse + OO Array

Postby Marcelo Via Giglio » Wed Jun 04, 2014 1:02 pm

Antonio,

the inherit from TdataBase is a good idea I will try.

The tDataSource Class will be the best way, I think is not late to implement it

Gracias por la respuesta Antonio y James

saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1050
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: xBrowse + OO Array

Postby Antonio Linares » Wed Jun 04, 2014 3:25 pm

Marcelo,

It seems easy to implement a Class TDataSource, the problem would be regarding the xbrowse that it is not designed for it.

Anyhow, Rao is our XBrowse expert, so he has the final word :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xBrowse + OO Array

Postby James Bott » Wed Jun 04, 2014 3:34 pm

I don't see any advantage to inheriting from TDatabase. Almost every method would have to be overridden anyway.

I wrote mine from scratch with all the same data and methods as TDatabase. As I mentioned before, I think the problem I found was with xBrowse needing an alias otherwise it treats the data class as an array instead of a database object.

I don't have my old notes with me right now, but I will try to remember to look them up tonight for more specific information.

It may be that creating a subclass of xBrowse would solve the problem.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xBrowse + OO Array

Postby Antonio Linares » Wed Jun 04, 2014 3:49 pm

James,

The only advantage is that xbrowse then would recognize the TDataArray as a TDataBase object too, and not as an array, anyhow as you explained, many methods would have to be overriden.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xBrowse + OO Array

Postby James Bott » Wed Jun 04, 2014 3:51 pm

Antonio,

What did you have in mind for a TDataSource class?

It seems to me that (ideally) all we need is to assign any data object to xBrowse. Since all data objects would have the same properties and methods then xBrowse would not need to handle all this internally. We could also use these non-dbf database classes anywhere else a DBF is normally used. So we could have an array class, a SQLite class, a MySQL class, etc.

A TDataSource class could be a parent class of these various types of classes that is never actually instantiated by itself, but rather just used as an inheritance source. I have seen this done before.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xBrowse + OO Array

Postby Marcelo Via Giglio » Wed Jun 04, 2014 3:53 pm

Antonio,

yes, tDataSource only need to be an skeleton like interface in java

and James, yes the solution is xBrowse, it needs to work with tDataSource structure

regards

Marcelo
Marcelo Via Giglio
 
Posts: 1050
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: xBrowse + OO Array

Postby Enrico Maria Giordano » Wed Jun 04, 2014 5:17 pm

James,

James Bott wrote:A TDataSource class could be a parent class of these various types of classes that is never actually instantiated by itself, but rather just used as an inheritance source. I have seen this done before.


Yes, in OOD they call it an "interface", if I remember correctly.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: xBrowse + OO Array

Postby James Bott » Wed Jun 04, 2014 6:03 pm

Enrico,

According to the book, "Business Engineering with Object Technology," by David A. Taylor, P 91, classes that never get instantiated themselves are called "abstract" classes. If they are instantiated themselves, then they are called "concrete" classes.

Perhaps they are also called "interface" classes.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xBrowse + OO Array

Postby Enrico Maria Giordano » Wed Jun 04, 2014 6:06 pm

James,

James Bott wrote:Enrico,

According to the book, "Business Engineering with Object Technology," by David A. Taylor, P 91, classes that never get instantiated themselves are called "abstract" classes. If they are instantiated themselves, then they are called "concrete" classes.

Perhaps they are also called "interface" classes.

James


Yes, right.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: xBrowse + OO Array

Postby Antonio Linares » Wed Jun 04, 2014 7:45 pm

James,

I have just been having a look at Borland's Class TDataSource:
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DB_TDataSource.html
and though it has many things that we don't need, we can get some ideas of what we could use.

I would propose a few of them:

Code: Select all  Expand view

CLASS TDataSource

   DATA  lAutoEdit INIT .F.

   METHOD New() INLINE Self

   METHOD GoTop() VIRTUAL
   METHOD GoBottom() VIRTUAL
   METHOD Skip( nRecords ) VIRTUAL
   METHOD Get() VIRTUAL
   METHOD Set() VIRTUAL
   METHOD Count() VIRTUAL
   METHOD GetPos() VIRTUAL // equivalent for RecNo()
   METHOD SetPos( nPos ) VIRTUAL // equivalent for GoTo()
   METHOD Edit() // Automatically build an editing interface

   METHOD OnDataChange() VIRTUAL
   
ENDCLASS
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: xBrowse + OO Array

Postby nageswaragunupudi » Fri Jun 06, 2014 4: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
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse + OO Array

Postby nageswaragunupudi » Sat Jun 07, 2014 2:31 am

In case you feel implementation of the above suggestion may take time and you want a quick start, please add this one method to your class:
Code: Select all  Expand view
METHOD SetXBrowse( oBrw, aCols, lAutoSort, lAutoCols ) CLASS TArray // (your class name)

   local aHead, n, nAt

   if aCols == nil
      lAutoCols   := .t.
      aHead       := ArrTranspose( ::aStruct )[ 1 ]
      aCols       := .t.
   else
      lAutoCols   := .f.
      aHead       := AClone( aCols )
      for n := 1 to Len( aCols )
         aCols[ n ]  := Max( 1, AScan( ::aStruct, { |a| Upper( aCols[ n ] ) == Upper( a[ 1 ] ) } ) )
      next n
   endif

   WITH OBJECT oBrw
      :SetArray( ::aData, lAutoSort, 1, aCols )
      :cHeaders      := aHead
      for n := 1 to Len( :aCols )
         WITH OBJECT :aCols[ n ]
            :cDataType     := ::aStruct[ n, 2 ]
            :nDataLen      := ::aStruct[ n, 3 ]
            :nDataDec      := ::aStruct[ n, 4 ]
            if ::cDataType == 'N'
               :cEditPicture  := NumPict( :nDataLen, :nDataDec )
            endif
         END
      next
   END

return oBrw
 

In the above code, please substitute
TArray with the name of your class.
::aStruct with the name of the DATA holding the structure
::aData with the name of the DATA holding the array data

Note: I did not test the code. Please correct if there are any syntax errors.

After adding this method you are ready to XBrowse your class just like any other browse.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 31 guests