How to store an array into a single database field?
Posted on 2011-10-18
I have a 2 dimensional array of enumerated values that are used to represent whether a staff member is willing to work or not on a given weekday in a four week period.
Prefstate = (negative=-1,neutral=0,positive=1);
PrefArray = array[1..4] of array[1..4] of PrefState;
I want to store this array in a single database field of the Staff table, in which each row represents one staff member but I don’t understand the syntax I need to do this. I have defined a field in the table as of type BYTE, and reserved 16 bytes (which is the value returned by sizeof(PrefArray)), and internally store the data in a record structure that is defined as:
StaffRec = record
Preferences : PrefArray;
var NS: StaffRec;
and after populating the fields attempt to save the data to the dataset:
srcStaff.DataSet.FieldValues['Preferences'] := NS.Preferences;
This line does not compile with error ‘E2010 Incompatible types: 'Variant' and 'PrefArray'’. Typecasting the array as a variant
srcStaff.DataSet.FieldValues['Preferences'] := variant(NS.Preferences)
compiles, but results in a run time error ‘Invalid variant type or size for field ‘Preferences’’.
I am using Delphi 2009, and the AbsoluteDB components from Component Ace.
Clearly I am missing something fundamental, and I would be grateful for any help or pointers in the right direction.