Hi Przemek,

> This code illustrates the difference between regular and
> associative hash arrays:
> 
>   proc main()
[...]
>   return
> 
> As you can see executing it the order of items in associative array
> is strictly defined and it's the same as the order in which new item
> were added. It means that you have two strictly defined indexes. One
> which can be used with [] operator and any hash item keys and the
> second numeric only index. It's usable in many different places.
> This is the part of ChangeLog message I created for Harbour OLE
> servers. It's very nice example of practical usage.

Thanks a lot, I got it now, so f.e. it's useful to have a data 
structure (like 'LOCAL hbmk' in hbmk2) with both numeric and 
string indexing, where numeric has the speed while string based 
has the advantage that it can be accessed without messing 
with headers, or most importantly to guarantee exact 
positions (f.e. external access). I faced partially similar 
"problem" in hbmk2 plugin system.

>   <hAction> is optional parameter with hash array containing messages
>   and instance variables used by OLE server. The keys in hash array
>   are strings with message names and values are actions. Codeblock
>   and symbol items means that given message is a method call and
>   any other value means that it's variable.
>   By default the same hash array is shared between all objects
>   created by registered server. It's important when hash array
>   contains values which are neither codeblock nor symbol items
>   so they are not used as method but rather as instance variables
>   because such instance variables are shared between OLE objects.
>   Setting 4-th parameter <lHashClone> to .T. causes that each
>   objects receives it's own copy of <hAction> item so instance
>   variables inside hash array are also local to OLE object.
>   Alternatively programmer can use <bAction> or <sAction> to create
>   seprate copy of hash array for each object, i.e.:
>      bAction := {|| hb_hClone( hValue ) }
>   When hash array contains symbol item (@funcName()) then when it's
>   executed by OLE object message it's possible to access the hash
>   array bound with given OLE object using QSelf() function. It maybe
>   useful if hash array contains instance variables and programmer
>   wants to access them.
>   Please remember that using hash array which was initialized to keep
>   original assign order by HB_HKEEPORDER( <hAction>, .T. ) before
>   adding its items you can define strict message numbers (DISPIDs), i.e.:
>      hAction := {=>}
>      HB_HKEEPORDER( hAction, .T. )
>      hAction[ "OPEN" ]  := @myole_open()     // DISPID=1
>      hAction[ "CLOSE" ] := @myole_close()    // DISPID=2
>      hAction[ "SAVE" ]  := @myole_save()     // DISPID=3
>      hAction[ "LOAD" ]  := @myole_load()     // DISPID=4
>      hAction[ "PRINT" ] := @myole_print()    // DISPID=5
>   (see example in olesrv2.prg)

Great stuff.

Viktor

_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to