FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Macro & OOP syntax
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Macro & OOP syntax
Posted: Thu Feb 28, 2008 02:39 AM
I find the following work as expected (just an illustration),
aOrders := {}
for i := 1 to 7
     cCnt := ltrim(str(i))
     aadd(aOrders, oDbf:order&cCnt)
next


Where in the end, aOrders would contain the value of oDbf:order1, oDbf:order2, oDbf:order3,....oDbf:order7. What annoys me is the reverse isn't true. That is, the following won't work.
for i := 1 to 7
     cCnt := ltrim(str(i))
     oDbf:order&cCnt := aOrders[i]
next


The values just seem can't be assigned to the database object. Can anyone shed a light on why it's so and a workaround? I'm hoping to avoid having to code it line by line as such
oDbf:order1 := aOrders[1]
oDbf:order2 := aOrders[2]
oDbf:order3 := aOrders[3]
                .
                .
                .
oDbf:order7 := aOrders[7]
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 464
Joined: Tue May 16, 2006 07:47 AM
Macro & OOP syntax
Posted: Thu Feb 28, 2008 10:00 AM
My guess would be (based on dim recollections of my C coding days) that the right hand side of the := is evaluated and the left hand side is taken to be in effect the storage location to which the result of that evaluation is stored. So the &cCnt isn't valid on the left hand side of the :=.

One possible workaround would be to use a combination of FieldPos() and FieldPut() in a method inside a method of CLASS Dbf.

FOR i := 1 to 7
   cCnt := ltrim( str( i ) )
   oDbf:AssignOrder( order&cCnt, aOrders[i] )
NEXT


and inside CLASS Dbf

METHOD AssignOrder (pName, pValue ) CLASS Dbf
   FieldPut( FieldPos( pName ), pValue )
RETURN nil


That assumes that you want to put the values directly into the (one) table.

I don't know enough about what you are really trying to do to be of more help, but personally I avoid using &. Why can't class Dbf use an array? Or should you have a sub-table? I'm only guessing, but maybe there's a more elegant solution waiting to be found.

Regards
xProgrammer
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Macro & OOP syntax
Posted: Thu Feb 28, 2008 12:39 PM
Hua,

Do it this way:
for i := 1 to 7 
     cCnt := ltrim(str(i)) 
     OSend( oDbf, "_order" + cCnt, aOrders[i] ) 
next
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Macro & OOP syntax
Posted: Fri Feb 29, 2008 01:55 AM
xProgrammer wrote:
One possible workaround would be to use a combination of FieldPos() and FieldPut() in a method inside a method of CLASS Dbf.

Thanks for the reply Doug :-) Yes, that's a valid suggestion but if I'm not mistaken, fieldpos() and fieldput() will read from the physical dbf. I'm trying to optimize the operations as everything is already in an array

xProgrammer wrote:
I don't know enough about what you are really trying to do to be of more help, but personally I avoid using &.

I'm in the midst of converting an old dos module to windows. I do avoid '&' like a plague but sometimes if I don't see any alternative I'll end up using it anyway.

xProgrammer wrote:
Why can't class Dbf use an array? Or should you have a sub-table? I'm only guessing, but maybe there's a more elegant solution waiting to be found.

Oh it does. The database class that comes with fivewin stores all the field values in oDbf:aBuffers though we access it in the form of oDbf:<fieldname>. This table should've been further normalized as the customers contact details and their orders are currently kept in the same table but for backward-compatibility sake I just maintain the structure as it is.

Here's to hoping to find an elegant solution :-)
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Macro &amp; OOP syntax
Posted: Fri Feb 29, 2008 01:56 AM
Antonio Linares wrote:
Do it this way:
for i := 1 to 7 
     cCnt := ltrim(str(i)) 
     OSend( oDbf, "_order" + cCnt, aOrders[i] ) 
next


Yes! That's it!. Thank you Antonio!
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion