BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Reflection

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TIllegalArgumentException
    • TInvalidEnumException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
    • IIterable
    • IIterator
    • ICloseable

    Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts

    Color

    • Introduction
    • SColor8
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • FileSystem

    • Introduction
    • IFileWalker
    • SFileAttributes
    • EFileWalkOption
    • EFileWalkResult
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • Glob

    • Introduction
    • EGlobOptions
    • TGlobIter
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
  • BRL.Math
  • Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject

    MaxUnit

    • Introduction
    • TTest
    • TAssert
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • Path

    • Introduction
    • TPath
    • IPathWalker
    • SPathAttributes
    • TPathDirIterator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PolledInput
  • BRL.RamStream
  • Random

    • Introduction
    • TRandomDefault

    RectPacker

    • Introduction
    • EPackingMethod
    • SPackedRect
    • TPackedSheet
    • TRectPacker

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Time

    • Introduction
    • ETimeUnit
    • TTimeoutException

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Pub

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • StdC

    • Introduction
    • SDateTime
  • Pub.xmmintrin

Collections

    IntMap

    • Introduction
    • TIntMap

    ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    ObjectMap

    • Introduction
    • TObjectMap

    PtrMap

    • Introduction
    • TPtrMap

    StringMap

    • Introduction
    • TStringMap

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

Math

    Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI

    Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

Net

    Http

    • Introduction
    • THttpClient
    • THttpRequest
    • THttpResponse
    • THttpResult
    • TUrl
    • ICompleteListener
    • ICookie
    • THttpClientException
    • THttpCookie
    • THttpCookieBuilder
    • THttpField
    • THttpFields
    • TRetryPolicy
    • TUrlBuilder
    • TContent
    • TStringContent
    • TStreamContent
    • TBytePtrContent
    • TByteArrayContent
    • TBankContent
    • TCAStore
    • ECookieAttribute
    • EHttpAuthMethod
    • EHttpHeader
    • EHttpMethod
    • EUrlCode
    • EUrlPart

Random

    Core

    • Introduction
    • TRandom
  • Random.PRVHASH
  • Random.Secure
  • SFMT

    • Introduction
    • TSFMTRandom
  • Random.Squares
  • Random.Xoshiro

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType

Text

    CP932Encoding

    • Text.CP932Encoding

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Encoding

    • Text.Encoding

    Format

    • Introduction
    • TFormatter

    Graphviz

    • Introduction
    • TGVGraphviz
    • TAGraph

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Markdown

    • Introduction
    • TMarkdown
    • IMDRenderer

    Pikchr

    • Introduction
    • EPikChrFlags

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute
Edit

BRL.Reflection

BlitzMax provides limited support for a form of runtime reflection.

Using reflection, programs can 'inspect' objects and types at runtime. You can determine the fields and methods contained in an object or type, set and get object fields and invoke - or 'call' - object methods.

To use reflection, you first need a TTypeId object. TTypeId objects correspond to BlitzMax user defined types, and there is a single TTypeId object for every user defined type in the program. There are also TTypeId objects for the 'primitive' types - byte, short, int, long, float, double and string. TTypeId objects are returned by the TTypeId.ForName and TTypeId.ForObject functions.

Once you have a TTypeId object, you can inspect the fields and methods of a user defined type using the EnumFields and EnumMethods methods. These methods return TField and TMethod objects that describe the fields and methods within the type. For example:

Strict

Type TMyType
    Field x,y,z
End Type

Local id:TTypeId=TTypeId.ForName( "TMyType" )

For Local fld:TField=EachIn id.EnumFields()
   Print fld.Name()+":"+fld.TypeId().Name()
Next

This simple program will print "x:Int", "y:Int" and "z:Int" - the names and types of the fields within TMyType. Note that this is done without actually creating a new TMyType.

The following example sets the fields of an object:

Strict

Type TMyType
    Field x,y,z
End Type

Local obj:TMyType=New TMyType
Local id:TTypeId=TTypeId.ForObject( obj )

For Local fld:TField=EachIn id.EnumFields()
    fld.Set obj,String( Rand(10) )
Next

Print obj.x+","+obj.y+","+obj.z

In this case we need an actual instance of TMyType, otherwise we have nothing to set the fields of! Also, we have used TTypeId.ForObject instead of TTypeId.ForName to get a TTypeId. While in this case TTypeId.ForName could have been used to achieve the same result, in general we may not know the exact type of the object, and therefore we wont know its type name.

Also note that the code that actually sets the fields uses String( Rand(10) ). This is because the Set method takes an object - but our fields are ints! BlitzMax reflection deals with this by using strings to represent numeric types. The same rule applies to the Get method. Any numeric fields will be returned as strings which you must then convert to the appropriate type if necessary.

Finally, let's invoke an object method:

Strict

Type TMyType
    Method Update( t# )
        Print "TMyType.Update:"+t
    End Method
End Type

Local obj:TMyType=New TMyType
Local id:TTypeId=TTypeId.ForObject( obj )

Local update:TMethod=id.FindMethod( "Update" )

update.Invoke obj,[String( .25 )]

This example uses FindMethod to locate a type method and Invoke to call it. Arguments to the method are contained in an object array, and again the float argument is converted to a string.

In addition to the TTypeId, TField and TMethod types, the BlitzMax reflection module also declares a number of global TTypeId objects:

  • ByteTypeId
  • ShortTypeId
  • IntTypeId
  • LongTypeId
  • FloatTypeId
  • DoubleTypeId
  • StringTypeId
  • ObjectTypeId

These may be used instead of the corresponding TTypeId.ForName call. For example, TTypeId.ForName( "Int" ) and IntTypeId will return the same object.

Types

TypeDescription
TMemberType member
TConstantType member constant
TFieldType member field
TGlobalType member global variable
TFunctionType member function
TMethodType member method
TTypeIdType ID

Globals

Global ByteTypeId:TTypeId = New TTypeId.Init("Byte", SizeOf Byte Null)

Primitive Byte type ID


Global ShortTypeId:TTypeId = New TTypeId.Init("Short", SizeOf Short Null)

Primitive Short type ID


Global IntTypeId:TTypeId = New TTypeId.Init("Int", SizeOf Int Null)

Primitive Int type ID


Global UIntTypeId:TTypeId = New TTypeId.Init("UInt", SizeOf UInt Null)

Primitive UInt type ID


Global LongTypeId:TTypeId = New TTypeId.Init("Long", SizeOf Long Null)

Primitive Long type ID


Global ULongTypeId:TTypeId = New TTypeId.Init("ULong", SizeOf ULong Null)

Primitive ULong type ID


Global SizeTTypeId:TTypeId = New TTypeId.Init("Size_T", SizeOf Size_T Null)

Primitive Size_T type ID


Global FloatTypeId:TTypeId = New TTypeId.Init("Float", SizeOf Float Null)

Primitive Float type ID


Global DoubleTypeId:TTypeId = New TTypeId.Init("Double", SizeOf Double Null)

Primitive Double type ID


Global ObjectTypeId:TTypeId = New TTypeId.Init("Object", SizeOf Byte Ptr Null, bbRefObjectClass, , False)

Object type ID


Global StringTypeId:TTypeId = New TTypeId.Init("String", SizeOf Byte Ptr Null, bbRefStringClass, ObjectTypeId)

String type ID


Global LParamTypeId:TTypeId = New TTypeId.Init("LParam", SizeOf LParam Null)

WinAPI LPARAM type ID

Only available on Windows.


Global WParamTypeId:TTypeId = New TTypeId.Init("WParam", SizeOf WParam Null)

WinAPI WPARAM type ID

Only available on Windows.


Global Int128TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrInt128)

Intrinsic Int128 type ID

Only available on x64.


Global Float64TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrFloat64)

Intrinsic Float64 type ID

Only available on x64.


Global Float128TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrFloat128)

Intrinsic Float128 type ID

Only available on x64.


Global Double128TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrDouble128)

Intrinsic Double128 type ID

Only available on x64.


Global VoidTypeId:TTypeId = New TTypeId.Init("", 0)

Primitive void type ID
Only used as a function/method return type


Global ArrayTypeId:TTypeId = New TTypeId.Init("Null[]", SizeOf Byte Ptr Null, bbRefArrayClass, ObjectTypeId, False)

Mock array base type ID


Global PointerTypeId:TTypeId = New TTypeId.Init("Ptr", SizeOf Byte Ptr Null, , , False)

Mock pointer base type ID


Global VarTypeId:TTypeId = New TTypeId.Init("Var", SizeOf Byte Ptr Null, , , False)

Mock var base type ID


Global FunctionTypeId:TTypeId = New TTypeId.Init("Null()", SizeOf Byte Ptr Null, , , False)

Mock function/method base type ID


← TRectPackerTTypeId →
  • Types
  • Globals
    • Global ByteTypeId:TTypeId = New TTypeId.Init("Byte", SizeOf Byte Null)
    • Global ShortTypeId:TTypeId = New TTypeId.Init("Short", SizeOf Short Null)
    • Global IntTypeId:TTypeId = New TTypeId.Init("Int", SizeOf Int Null)
    • Global UIntTypeId:TTypeId = New TTypeId.Init("UInt", SizeOf UInt Null)
    • Global LongTypeId:TTypeId = New TTypeId.Init("Long", SizeOf Long Null)
    • Global ULongTypeId:TTypeId = New TTypeId.Init("ULong", SizeOf ULong Null)
    • Global SizeTTypeId:TTypeId = New TTypeId.Init("Size_T", SizeOf Size_T Null)
    • Global FloatTypeId:TTypeId = New TTypeId.Init("Float", SizeOf Float Null)
    • Global DoubleTypeId:TTypeId = New TTypeId.Init("Double", SizeOf Double Null)
    • Global ObjectTypeId:TTypeId = New TTypeId.Init("Object", SizeOf Byte Ptr Null, bbRefObjectClass, , False)
    • Global StringTypeId:TTypeId = New TTypeId.Init("String", SizeOf Byte Ptr Null, bbRefStringClass, ObjectTypeId)
    • Global LParamTypeId:TTypeId = New TTypeId.Init("LParam", SizeOf LParam Null)
    • Global WParamTypeId:TTypeId = New TTypeId.Init("WParam", SizeOf WParam Null)
    • Global Int128TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrInt128)
    • Global Float64TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrFloat64)
    • Global Float128TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrFloat128)
    • Global Double128TypeId:TTypeId = New TTypeId.InitStruct(DebugScopePtrDouble128)
    • Global VoidTypeId:TTypeId = New TTypeId.Init("", 0)
    • Global ArrayTypeId:TTypeId = New TTypeId.Init("Null[]", SizeOf Byte Ptr Null, bbRefArrayClass, ObjectTypeId, False)
    • Global PointerTypeId:TTypeId = New TTypeId.Init("Ptr", SizeOf Byte Ptr Null, , , False)
    • Global VarTypeId:TTypeId = New TTypeId.Init("Var", SizeOf Byte Ptr Null, , , False)
    • Global FunctionTypeId:TTypeId = New TTypeId.Init("Null()", SizeOf Byte Ptr Null, , , False)
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
Resources
More
GitHubStarChat on Discord
Copyright © 2026 Bruce A Henderson