PDA

View Full Version : Suggestion regarding tNameValuePair



Sture
27-Aug-2018, 11:24 AM
I suggest moving the functions that operates on tNamedValuePair values from cWebObject to a new mixin class in a seperate package.

Then I'd be able to use these guys:


Function NamedValueIndex tNameValuePair[] Data String sName Returns Integer
Function NamedValueGet tNameValuePair[] Data String sName Returns String
Function NamedValueAdd tNameValuePair[] Data String sName String sValue Returns tNameValuePair[]
Function NamedValueRemove tNameValuePair[] Data String sName Returns tNameValuePair[]


regardless of having a cWebObject object at hand or not.

-Sture

Sture
27-Aug-2018, 11:29 AM
On second thoughts. It's only 50 lines of code.

-Sture

raveens
4-Sep-2018, 06:54 PM
IMHO, maybe just moved those to a GLOBAL declaration ?

We are using the tNameValuePair everywhere including WinApps - its brilliant/simple/robust!
We even found the tWebNavigateData useful in WinApps, especially in Prompt_Callbacks

So we ended up with a tNavigateData.pkg that looks something like:



#IF (!@ > 180)
Use tWebNavigateData.pkg
#ELSE
// Used when navigating to a view in a drill-down view stack.
// Passes the necessary data Between views


// String Name / Value pair
Struct tNameValuePair
String sName
String sValue
End_Struct


Struct tWebNavigateData
String sRowID // RowId of current value in iTable member
Integer iTable // Table number for ridRowID member
Integer iColumn // Focused column number fot the iTable member
Integer eNavigateType // drill-down navigate from type (e.g. nfFromMain, nfFromParent)
Boolean bNewRecord // Used when navigating to a zoom with the intention of creating a new record
Boolean bReadOnly // Used when navigating to a zoom to instruct the zoom to initially display itself Read-Only
Boolean bSaveBeforeNavigate // if set true, the view is saved before forward navigation
tNameValuePair[] NamedValues
End_Struct


#ENDIF




#IFDEF IS$WEBAPP
#ELSE // WinApp
// return index named value
Function NamedValueIndex Global tNameValuePair[] Data String sName Returns Integer
Integer iIndex
tNameValuePair NameValuePair
Move (Uppercase(sName)) to NameValuePair.sName
Move (SearchArray(NameValuePair,Data)) to iIndex
Function_Return iIndex
End_Function


// return value for name, if not found, returns ""
Function NamedValueGet Global tNameValuePair[] Data String sName Returns String
Integer iIndex
Get NamedValueIndex Data sName to iIndex
Function_Return (If(iIndex=-1, "" , Data[iIndex].sValue))
End_Function


// Add name/value pair. If the Name exists, replace value, else append to end
Function NamedValueAdd Global tNameValuePair[] Data String sName String sValue Returns tNameValuePair[]
tNameValuePair NameValuePair
Integer iIndex
Move (Uppercase(sName)) to NameValuePair.sName
Move sValue to NameValuePair.sValue
Move (SearchArray(NameValuePair,Data)) to iIndex
If (iIndex=-1) Begin
Move (SizeOfArray(Data)) to iIndex
End
Move NameValuePair to Data[iIndex]
Function_Return Data
End_Function


// remove name/value pair if name exists.
Function NamedValueRemove Global tNameValuePair[] Data String sName Returns tNameValuePair[]
Integer iIndex
tNameValuePair NameValuePair
Move (Uppercase (sName)) to NameValuePair.sName
Move (SearchArray (NameValuePair, Data)) to iIndex
If (iIndex <> -1) Begin
Move (RemoveFromArray (Data, iIndex)) to Data
End
Function_Return Data
End_Function


#ENDIF





Works well for us, but I would like DAW to come to the party here.

seanyboy
5-Sep-2018, 08:25 AM
We wrap the Dictionary OCX provided by microsoft in

C:\Windows\SysWOW64\scrrun.dll

And then we use

get KeyValue of hDict "Name" to iValue
Send AddKey to hDict "Name" iValue

to get and set dictionary values. I've pushed over 1.5GB of data into a single dictionary, and for large data sets, it's much speedier than using an Array.


I would however, prefer a native language hashmap that works in the same way as an array.
e.g.



string[""] hmNames
move "Value" to hmNames["Name"]
move (hmNames["Names"] = "Value") to isFound

wila
5-Sep-2018, 10:35 AM
Associative arrays would indeed be nice to have.
Somehow it matches great with JSON too. :p

Even some other database servers (mongoDB) would suddenly make more sense too.

--
Wil

Mike Peat
5-Sep-2018, 11:24 AM
Maybe I'm missing the point, but...

Rather than:



Struct tNameValuePair
String sName
String sValue
End_Struct

Property tNameValuePair[] patNameValues


I tend to write:



Property String[] pasNames
Property String[] pasValues


Then I can do:



Procedure UpdatePair String sName String sValue
Integer iPos
String[] asNames asValues

Get pasNames to asNames
Get pasValues to asValues

Move (SearchArray(sName, asNames)) to iPos

If (iPos < 0) ;
Move (SizeOfArray(asNames)) to iPos

Move sName to asNames[iPos]
Move sValue to asValues[iPos]

Set pasNames to asNames
Set pasValues to asValues
End_Procedure

Function FindValue String sName Returns String
Integer iP, asNamesos
String[] asNames asValues

Get pasNames to asNames
Get pasValues to asValues

Move (SearchArray(sName, asNames)) to iPos

If (iPos > -1) ;
Function_Return (asValues(iPos))

Function_Return ""
End_Function

Function FindName String sValue Returns String
Integer iPos
String[] asNames asValues

Get pasNames to asNames
Get pasValues to asValues

Move (SearchArray(sValues, asValues)) to iPos

If (iPos > -1) ;
Function_Return (asNames(iPos))

Function_Return ""
End_Function

Procedure RemovePair String sName
Integer iPos
String[] asNames asValues

Get pasNames to asNames
Get pasValues to asValues

Move (SearchArray(sName, asNames)) to iPos

If (iPos > -1) Begin
Move (RemoveFromArray(asNames, iPos))
Move (RemoveFromArray(asNames, iPos))
Set pasNames to asNames
Set pasValues to asValues
End

End_Procedure


Pretty dumb, I'll grant, but... I like dumb! :rolleyes:

Mike

raveens
5-Sep-2018, 01:37 PM
Hi Mike,

The above is a straight one-to-one extraction of DAW's tNameValuePair routines from the cWebObject.pkg file, moved into a global declaration so that we can use the same functionality in WinApps, rather than just for WebApps.

Marco
5-Sep-2018, 05:29 PM
I find all of the above interesting, but agree the most with Raveen’s request, that seems simple enough to implement by DAW in a short timeframe.

Having the existing value pair logic in win apps alllows these to be used in libraries, which would be my main 1+

Dennis Piccioni
6-Sep-2018, 10:09 AM
Hi Sture,

your suggestion is logged.

Todd Forsberg
6-Sep-2018, 03:46 PM
Can you log Raveen's suggestion also?

Dennis Piccioni
7-Sep-2018, 02:31 PM
They are pretty closely related and in the same thread. Whoever implements this will review that together.

Todd Forsberg
12-Sep-2018, 07:37 AM
ok. Fair enough.