Data Access Worldwide Knowledge Base
Article ID 2071 Article Title HOWTO: Determine the size of a string from its address Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2071 KBase Category VDF (GENERAL) Date Created 12/10/2004 Last Edit Date 12/15/2004
Article Text
QUESTION:
I have the address of a string. How I can determine the size of the data starting at that address?
ANSWER:
Let's assume that the string is terminated by a zero byte (Ascii(0)). You can find out the size of the string by testing for the first zero byte in it by doing the following:
Function SizeOfData Address aData Returns Integer
Integer iPos
Repeat
Increment iPos
Until (DeRefC (aData, iPos) = 0)
Function_Return iPos
End_Function // SizeOfData
Example of the usage:
Get XSLTransformationToAddress Of hoXMLRoot hoXSLSource To aResult
If (aResult > 0) Begin
Get SizeOfData aResult To iDataSize
If the information is not in a DataFlex string and you want to copy that information from the pointer (address) to a DataFlex variable, you can make use of the following function (taken from cMapiHandler class) that copies the information to a DataFlex string:
Function CopyPointerToDfString Pointer lpsDataPointer Returns String
String sResult sCharacter
Integer iVoid
Pointer pCharacter
If (lpsDataPointer <> 0) Begin
ZeroString 1 To sCharacter
GetAddress Of sCharacter To pCharacter
Move (CopyMemory (pCharacter, lpsDataPointer, 1)) To iVoid
While (Ascii (sCharacter) <> 0)
Move (sResult + sCharacter) To sResult
Increment lpsDataPointer
Move (CopyMemory (pCharacter, lpsDataPointer, 1)) To iVoid
End
End
Function_Return sResult
End_Function // CopyPointerToDfString
The above is copying the information byte-by-byte.
NOTES:
1) The default maximum size of a local DataFlex string is 64KB (since VDF7) and the command SET_ARGUMENT_SIZE can be used to change this.
2) The above CopyPointerToDfString will therefore - if the argument size is not changed - only copy the first 65535 bytes.
Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.