Typecast SET to INTEGER ? 
Author Message
 Typecast SET to INTEGER ?

I realize that this is not a true database question, but most of my work
is in database and I tend not to follow the other delphi Groups.

Altho there must be a simple way to typecast an integer to a set and
visa versa, I can't seem to get it.  Read the docs, etc.  Have not had
this prob with other languages.  I can think of inelegant ways to do it,
but I much prefer simple elegance.

Any suggestions?

Thx,

Joe

--
==============================================
Joe Steponaitis         Phone: 902 826-7483
FENIX Software          Fax..: 902 826-1404

Boutilier's Point,
Nova Scotia
CANADA  B0J 1G0         Waaas Sapeneeen???????
==============================================



Mon, 21 Dec 1998 03:00:00 GMT  
 Typecast SET to INTEGER ?


Quote:

>I realize that this is not a true database question, but most of my work
>is in database and I tend not to follow the other Delphi Groups.

>Altho there must be a simple way to typecast an integer to a set and
>visa versa, I can't seem to get it.  Read the docs, etc.  Have not had
>this prob with other languages.  I can think of inelegant ways to do it,
>but I much prefer simple elegance.

>Any suggestions?

>Thx,

>Joe

Hi Joe,

I have tried it and it should work:

procedure TForm2.HCButton1Click(Sender: TObject);
TYPE TXX = (A, B, C, D, E, F, G, H, I, J, K);
    TSetOfXX = Set Of TXX;
VAR
    AnySet : TSetOfXX;
    wSet : Word;
begin
  AnySet := [A, B, C, D, E, F, G, H, I];
  wSet := Word (AnySet);
end;

Hope it helps

Bye

Andreas

=============================================
helicon software development - Andreas Prucha

=============================================



Tue, 22 Dec 1998 03:00:00 GMT  
 Typecast SET to INTEGER ?



Quote:
>I realize that this is not a true database question, but most of my work
>is in database and I tend not to follow the other Delphi Groups.

>Altho there must be a simple way to typecast an integer to a set and
>visa versa, I can't seem to get it.  Read the docs, etc.  Have not had
>this prob with other languages.  I can think of inelegant ways to do it,
>but I much prefer simple elegance.

   IntValue := Byte(SetValue); { for a set with up to 8 elements }

Post the exact code that causes problems, so we can help you.
Otherwise, we can only guess...
--

Tempest Software, Corvallis, Oregon, USA  http://www.tempest-sw.com



Tue, 22 Dec 1998 03:00:00 GMT  
 Typecast SET to INTEGER ?



Quote:
>I have tried it and it should work:

>procedure TForm2.HCButton1Click(Sender: TObject);
>TYPE TXX = (A, B, C, D, E, F, G, H, I, J, K);
>    TSetOfXX = Set Of TXX;
>VAR
>    AnySet : TSetOfXX;
>    wSet : Word;
>begin
>  AnySet := [A, B, C, D, E, F, G, H, I];
>  wSet := Word (AnySet);
>end;

Close, but only half of the sigar.

A set can contain up to 256 values, so you'll need 32 bytes to hold the
hold shebang (sp?)...

Some experimental code:
{$APPTYPE CONSOLE}
var
  s:set of byte;
  a:array[0..31] of byte;
  i:integer;
begin
  s:=[4, 5, 133];
  for i:=0 to sizeof(s)-1 do
  begin

    write(a[i], ' ');  //bit 4 and 5 is set in the first byte = 48
  end;
  //now the other way, from array to the set:
  s:=[];
  for i:=0 to sizeof(s)-1 do
  begin

    p^:=a[i];
  end;
end.

--
=\

=/



Tue, 29 Dec 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Delphi newbie: Integer to extended typecast

2. Q: Oracle ODBS ans ENABLE INTEGER setting, where ?

3. Can I Get then integer value of the menber of one set

4. Setting Higher order Bits for Integer Variable

5. Setting Higher order Bits for Integer Variable

6. storing a list of integers in one integer.

7. Q: How do you typecast an integer to an extended variable?

8. Invalid Class Typecast

9. SQL-Typecasting to boolean ?

10. value typecasts

11. A question about typecasting

12. typecasting preferences

 

 
Powered by phpBB® Forum Software