Xbasic
STRUCT_SET Function
STRUCT_SET() is deprecated and slated for removal in a future release.
Syntax
Structure as P = STRUCT_SET(C stucture_name[,B blob])
Arguments
- stucture_name
The name of a structure created with a DECLARESTRUCT definition. Character
- blob
Optional. Default = Null. The data to put into the structure.
Description
STRUCT_SET() creates a packed structure based on a DECLARESTRUCT definition, and optionally reads blob data to initialize the packed structure. This is useful for interpreting binary data read in from files.
Example
This following snippet of code reads the bitmap header structure from a bitmap file declare into the bitmap file header structure.
declarestruct BITMAPFILEHEADER C2Type, L1Size, W2Reserved, L1OffBits ? name of bitmap file is stored in a character variable dim shared bitmapfilename as C ? open the bitmap file f = file.open(bitmapfilename, FILE_RO_SHARED) ? use STRUCTURE_SET with no blob to create a structure bitmapfile = struct_set("BITMAPFILEHEADER") ? which we then use to create a blob bitmapfiledata = struct_get(bitmapfile) ?which we use to determine the size we need to read bitmapfiledata = f.readb(bitmapfiledata.size() ) ? convert the blob to the structure bitmapfile = struct_set("BITMAPFILEHEADER", bitmapfiledata) ? close the file f.close()
See Also