Function: DFRecnumToRowId
Hi
If anyone is interested, here's a function that converts the good old RECNUM to a ROWID
I generally use to when populating a cCJGrid via an SQL Statement - when the dataSource RowId needs to be populated.
[U]Usage:[/U]
Get SQLColumnValue Of hstmt 1 To iRecnum
Get CreateDataSourceRow of hoDataSource to aRowData
Move (DFRecnumToRowId(iRecnum)) to aRowData.riID
[CODE]
Function DFRecnumToRowId Global Integer iDec Returns RowID
String sHex
String sRet
Integer iCnt
Move "" to sHex
While (iDec>0)
Move (Mid("0123456789ABCDEF", 1, ((iDec iand |CI$0F) + 1)) + sHex) to sHex
Move (iDec / 16) to iDec
Loop
If (sHex="") Move "0" to sHex
Move (Lowercase(Right("00000000"+sHex,8))) to sHex
For iCnt from 1 to 4
Move (Insert(Mid(sHex,2,(iCnt*2)-1),sRet,1)) to sRet
Loop
Function_Return (DeserializeRowID(sRet))
End_Function
[/CODE]
Re: Function: DFRecnumToRowId
[Code]
Use UI
External_Function wvsprintf "wvsprintfA" USER32.DLL Pointer pResult String sTemplate Pointer pParam Returns Integer
External_Function htonl "htonl" Ws2_32.dll Uinteger u Returns UInteger
Function DFRecnumToRowId Global UInteger uDec Returns RowId
Integer iVoid
String sResult
Move (htonl(uDec)) to uDec
Move (Repeat(" ",9)) to sResult
Move (wvsprintf(AddressOf(sResult), "%.8lx", AddressOf(uDec))) to iVoid
Function_Return (DeserializeRowID(Left(sResult,8)))
End_Function
[/Code]
Used APIs to help out with the byte swap and int-to-hex conversion.
Frank Cheng
Re: Function: DFRecnumToRowId
Frank
I think you have the wrong return type on the reworked function.
It should be a RowID
Re: Function: DFRecnumToRowId
Chris,
I corrected the original reply. Thanks.
Frank Cheng