Skip to content

Type Obsolete Command

Type

Obsolete

The Type command is obsolete. See the Struct command for creating and using structured types in DataFlex.

Be aware of existing code using Type. Type definitions convert signed values to unsigned; structs do not. This could impact your code after converting to structs, where signed values were previously converted.

Example

Here is an example of converting an External_Function call using a Type to one using Structs:

Obsolete Code:

External_Function GetVersionExEf "GetVersionExA" kernel32.dll Pointer pOsVersionInfo Returns Integer

TYPE tOsVersionInfo
    Field tOsVersionInfo.dwOSVersionInfoSize as DWord
    Field tOsVersionInfo.dwMajorVersion as DWord
    Field tOsVersionInfo.dwMinorVersion as DWord
    Field tOsVersionInfo.dwBuildNumber as DWord
    Field tOsVersionInfo.dwPlatformId as DWord
    Field tOsVersionInfo.szCSDVersion as Char 128
END_TYPE

Procedure Test
    Handle hWnd
    Integer iRet iState iMajorVersion
    String sVersionInfo

    ZeroType tOsVersionInfo to sVersionInfo  // not needed when using Structs
    Put tOsVersionInfo_Size to sVersionInfo at tOsVersionInfo.dwOsVersionInfoSize  // not needed when using Structs
    Move (GetVersionExEf(addressof(sVersionInfo))) to iRet

    // now you can query the data inside the tOsVersionInfo Type for the return values
    // from the external function call using GetBuff:
    GetBuff from sVersionInfo at tOsVersionInfo.dwMajorVersion to iMajorVersion  // not needed when using Structs
    Send Info_Box (String(iMajorVersion)) "Major OS Version"
End_Procedure

New Code:

External_Function GetVersionExEf "GetVersionExA" kernel32.dll Pointer pOsVersionInfo Returns Integer

Struct tOsVersionInfo
    DWord dwOSVersionInfoSize
    DWord dwMajorVersion
    DWord dwMinorVersion
    DWord dwBuildNumber
    DWord dwPlatformId
    Char[128] szCSDVersion
End_Struct

Procedure Test
    Handle hWnd
    Integer iRet iState iMajorVersion
    tOsVersionInfo OSVersionInfo
    Pointer lpOSVersionInfo

    Move (SizeOfType(tOsVersionInfo)) to OSVersionInfo.dwOsVersionInfoSize
    Move (AddressOf(OSVersionInfo)) to lpOSVersionInfo
    Move (GetVersionExEf(lpOSVersionInfo)) to iRet

    // you can directly access the data inside the OSVersionInfo Struct for the return values
    // from the external function call
    Send Info_Box (String(OSVersionInfo.dwMajorVersion)) "Major OS Version"
End_Procedure

See Also

Purpose

To declare a structure for use with DLL calls from DataFlex programs.

Syntax

type
    TypeName
    field
        FieldName as DataType
end_type

Argument Explanation

  • TypeName: The name of the complex data type.
  • FieldName: The name of a field. There can be as many fields in the Type declaration as you wish.
  • DataType: Any DataFlex representation of a 'C' data type.

What It Does

Type enables you to create a complex data structure in memory for use in passing parameters for DLL calls from DataFlex programs.

type tv_item
    field tv_item.mask         as DWORD
    field tv_item.hItem        as HANDLE
    field tv_item.state        as DWORD
    field tv_item.stateMask    as DWORD
    field tv_item.pszText      as POINTER
end_type

In this example, the complex data structure tv_item is declared. In it, fields tv_item.mask, tv_item.state, and tv_item.pszText are declared as DWORDs, tv_item.hItem is a HANDLE, and tv_item.pszText is a POINTER.

Note

  • If you declare a structure, the size of the structure is automatically stored in a symbol called _Size.