SizeOf - Retrieve the size (byte count) of a string or a structure

Top  Previous  Next

Syntax

 

<nSize> := SizeOf( <inStringOrStructure> )

 

Parameters

 

<inStringOrStructure>

 

A string or a structure object whose size should be determined.

 

Return value

 

The length of the passed string or the size of the passed structure's data buffer. 

 

Description

 

If a string is passed to SizeOf, its size (byte count) is the return value. If an object is passed, its :buffersize member variable is queried and returned.

 

Classification

 

Core

 

Category

 

Miscellaneous

 

Quick Info

 

Library: cckptcor.lib / cckptcor.dll

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "ExtendedStructures.ch"

 

* Set up a simple structure

MEMBERLIST TESTSTRUCTURE

MEMBER word1

MEMBER byte1

ENDMEMBERLIST

 

STRUCTURE TESTSTRUCTURE

WORD word1

BYTE byte1

ENDSTRUCTURE

 

 

FUNCTION Main

 

LOCAL stru,string

 

* This will return 4 because of alignment

? SizeOf(TESTSTRUCTURE())

stru := TESTSTRUCTURE():New()

stru:word1 := 1

stru:byte1 := 2

 

* Access the buffer

string := stru:buffer

? SizeOf(string)

 

* Let's try with a string

tmp := "Test"

? SizeOf(tmp)

 

RETURN NIL