problem in migration from xHarbour in FOR EACH with hash

219 views
Skip to first unread message

Quique .

unread,
Oct 13, 2011, 11:25:59 PM10/13/11
to Foro de usuarios de harbour
I use very much FOR EACH with hash, but xHarbor use
 
FOR EACH oEach IN hash
   ? oEach:key(), oEach:value()
NEXT
 
Harbour uses a diffren sintax, but as I can see, hbcompat.ch doesn't fix it. Is it possible to correct this syntax the easy way? Or is it code that I have to modify in all places where it appears?

Przemysław Czerpak

unread,
Oct 14, 2011, 2:24:34 AM10/14/11
to harbou...@googlegroups.com
On Thu, 13 Oct 2011, Quique . wrote:

Hi,

> I use very much FOR EACH with hash, but xHarbor use FOR EACH oEach IN hash

> ? oEach:key(), oEach:value()NEXT Harbour uses a diffren sintax, but as I can see,


> hbcompat.ch doesn't fix it. Is it possible to correct this syntax the easy way?
> Or is it code that I have to modify in all places where it appears?

xHarbour does not support hash tables in FOR EACH directly.
Instead for each item of iterated hash table it creates HASHENTRY
object which has the following public methods:
<iterator>:VALUE
<iterator>:KEY
<iterator>:HPARENT
which are initialized on each iteration.
Harbour has native support for hash tables in FOR EACH without any
intermediate objects which is much faster and uses the same interface
for all iterated types (string, arrays and hash tables).
It's possible to use:
<iterator>:__enumValue // in xHarbour it's <iterator>:VALUE
<iterator>:__enumKey // in xHarbour it's <iterator>:KEY
<iterator>:__enumBase // in xHarbour it's <iterator>:HPARENT
<iterator>:__enumIndex // in xHarbour it's HB_ENUMINDEX()
// but it cannot be used in nested
// FOR EACH loops to check outer FOR EACH
// indexes.
But as for all other types you can access hash table items directly
by <iterator> item and you do not have to use <iterator>:__enumValue

There is no way to create PP rule which can hide differences between
Harbour and xHarbour without breaking other code so there is no chance
that they can appear in hbcompat.ch

best regards,
Przemek

Quique

unread,
Oct 17, 2011, 11:59:18 AM10/17/11
to Harbour Users
Thanks you
Reply all
Reply to author
Forward
0 new messages