> > Hi all...
> >
> > I have an enumerated set that I want to store in a db... I
> was assuming
> that
> > the items in the set could be converted to an integer. I
> thought each item
> > in the set was like a logical bit (and that was why the
> number of items in
> a
> > set was restricted).
> >
> > So if I had a type TSomeTime = set of (stOne, stTwo, stThree),
> > then I had a var SomeType: TSomeType,
> > then I could go something like SomeType := [stOne, stTwo]
> and somehow
> > convert this to an integer to store in a DB...
> >
> > But, the compiler doesn't like this, works ok for
> enumerated types, but
> not
> > for a set of them.
> >
> > Any tips on a nice way of storing a set type in a database field???
> >
> > Any suggestions welcome.
> >
You can always use this old but tested method....
{*************************************************}
procedure TForm1.Button1Click(Sender: TObject);
type
b = set of (AA,AB,AC,AD,AE);
var
a : record
case boolean of
true : (t : b);
false : (j : integer);
end;
begin
a.j := 0; { Clear it all out }
a.t := [];{ Paranoia }
a.t := [aa,ab];
{ At this point a.j = 3 }
a.t := a.t + [ac,ad];
{ At this point a.j = 15 }
end;
{*************************************************}
You just can't assume bit positions.
Particularly when using subset of integers
IE:
a = Set 5..12;
or when the set has > 8 elements(As intel chip flip bytes all over the
place)
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"