Hello, Good Morning! As you said , by default Enum type is 8-bit in BP.The Enumsize can be controlled by compiler directive {$Z} in Delphi.
{$Z1} or {$Z2} or {$Z4} {$MINENUMSIZE 1} or {$MINENUMSIZE 2} or {$MINENUMSIZE 4} Default {$Z1} {$MINENUMSIZE 1} The $Z directive controls the minimum storage size of enumerated types. An enumerated type is stored as an unsigned byte if the enumeration has no more than 256 values, and if the type was declared in the {$Z1} state (the default). If an enumerated type has more than 256 values, or if the type was declared in the {$Z2} state, it is stored as an unsigned word. Finally, if an enumerated type is declared in the {$Z4} state, it is stored as an unsigned double-word.
The {$Z2} and {$Z4} states are useful for interfacing with C and C++ libraries, which usually represent enumerated types as words or double-words.
Note: For backwards compatibility with earlier versions of Delphi and Borland Pascal, the directives {$Z-} and {$Z+} are also supported. They correspond to {$Z1} and {$Z4}, respectively.
How can we set size of enumerated data type in GPC?.Because in GPC, even if we give 2 values (0..1) also, it assigns 4 bytes by default.
Have a Nice Day!
Thanking You, Kind Regards, Karthic and Hari
Frank Heckenbach wrote:
Anuradha wrote:
Hello,
Sorry for the last mail.We are resending it.
We have a problem as follows. We have a database file tabinfo.mdb created under WINDOWS using pervasive SQL(Btrieve).Now we are trying to access it with GPC. We fear that there is some allignment problem in the records stored and the record passed to read data out. The record we used to create the tabinfo in windows is :
MDB_MLTABL_TYPE = RECORD MLTABLNM : CHAR_8 ; RID : word ; LENPHYS : word ; PHYSINF : PH_ADDR ; EDITION : BYTE ; DATALEV : FS_FILE_TYPE ; MLTABDES : PH_ADDR ; ATTCOUNT : BYTE ; ATTINFO : ARRAY [ 1..MAX_ATTRIBS ] OF MDB_ATTR_INFO_TYPE ; RELFILES : ARRAY [ 1..MAX_RELFILES ] OF MDB_REL_FILE_TYPE ; END ;
We use the same record structure to read data back from it (but in GPC).But it doesnot read properly. Can you tell us why this happens? BTW, fs_file_type is a Enumerated type . ph_addr is longint. (We have given longint=int32 word=word16 in our program).
First of all, declare the record and the sub-arrays and sub-records (if any; I don't know what MDB_ATTR_INFO_TYPE etc. is) as `packed' (and be aware of the inefficiencies involved -- the first field seems to a a single byte, so the following fields will be at odd addresses which is clearly less efficient on IA32 and much less efficient on RISCs; I guess you don't have much choice here, but if you do serious processing, you might want to copy the data in/out of the packed structure).
Then check the sizes of each field, using `SizeOf', and use `Integer (n)' or `Cardinal(n)' in GPC for a type of size n bits.
For the enum field, you'll probably have to use `Cardinal(8)' (if the other compiler makes it 8 bits big), since otherwise GPC would pack it as small as possible (e.g., 4 bits if it has 9 .. 16 values).
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html