![]() Timo\Next = When using the pointer, the '*' is omitted Debug Timo\Next\Name$ Will print 'Fred' *Next.Person Here the '*' is mandatory to declare a pointer Debug MyVar\c(0,10) Out-of-bounds index error ReDim MyVar\ c(3,10) Beware, only the last dimension can be resized! Debug MyVar\ c(0,10) Cool, the array is bigger now!Įxample: Nested structure(s) Structure pointFĮxample: Alignment Structure Type Align 4ĮndStructure Debug OffsetOf(Type\Byte) will print 0 Debug OffsetOf(Type\Word) will print 4 Debug OffsetOf(Type\Long) will print 8 Debug OffsetOf(Type\Float) will print 12 Procedure MyProcedure(*blahblah.Whatever) Now, add some friends to John AddElement(John\ Friends$())Įxample: Static, dynamic array and passing a structure to a procedure Structure Whateverī.l Static array (Standard C) with 2 values b and b, not resizable Array c.l(3,3) Dynamic array with 16 values c(0,0) to c(3,3), resizable with ReDim() EndStructure Name.s 10 Names available (from 0 to 9) EndStructureĮxample: Extended structure Structure MyPointĮndStructure Structure M圜oloredPoint Extends MyPointĬoloredPoint.M圜oloredPoint\color = RGB(255, 0, 0)Įxample: Structure copy Structure MyPoint *NextWindow.Window Points to another window object Here the position '0' of the array MyFriend() will contain one person and it's own information MyFriends(0)\Name = "Andersson"Įxample: A more complex structure (Nested and static array) Structure Window Keywords to reduce the amount of code to type and ease its readability. When using a lot of structure fields you can use the With : EndWith Seen as an oddity (and to be honest, it is) but it's like that since the very start of PureBasic and many, many sources rely When using pointers in structures, the '*' has to be omitted when using the field, once more to ease API code porting. This means that a willĪllocate an array from 0 to 1 where Dim a (2 ) will allocate an array from 0 to 2. To be conform to the C/C++ structure format (to allow direct API structure porting). Please note, that in structures a static array doesn't behave like the normal BASIC array (defined using Dim) ![]() SizeOf can be used with structures to get the size of the structure and OffsetOf can be used to retrieve The special value #PB_Structure_AlignC can be used to align the structureĪs it would be done in language C, useful when importing C structures to use with API functions. It can help to get more performance while accessing structure fields, but it can use more memory, as some spaceīetween each fields will be wasted. For example, if the alignment is set to 4, every field offset will be on a 4 byte boundary. The optional Align parameter allows to adjust alignment between every structure field. This is useful to do basic inheritance of structures.įor advanced users only. ![]() All fieldsįound in the extended structure will be available in the new structure and will be placed before The optional Extends parameter allows to extends another structure with new fields. It's possible to perform a full structure copy by using the equal affectation between two structure element of the same type. It is also possible to initialize a structure in memory withĬlearStructure() and reinitialize it with ![]() Memory structure with AllocateStructure() and free it with FreeStructure(). However, advanced users will be able to allocate a Generally, structures are used in association with a variable, an To declare such field, use the following keywords: When the object using the structure is created. Statics arrays are supported inside structures.ĭynamic objects like arrays, lists and maps are supported inside structure and are automatically initialized Structures fields are accessed with the \ option. It is very useful as you can group into the same To enable faster and easier handling of data files. Structure is useful to define user type, and access some OS memory areas.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |