Fórum Conjuntos (set) #209245
25/01/2004
0
[b:bdeb4f9030]Var[/b:bdeb4f9030]
x: [color=red:bdeb4f9030][b:bdeb4f9030]set of[/b:bdeb4f9030][/color:bdeb4f9030] 0..5;
a: [b:bdeb4f9030]string[/b:bdeb4f9030];
[b:bdeb4f9030]begin[/b:bdeb4f9030]
x:= [5];
a:= TypeCast [b:bdeb4f9030]????[/b:bdeb4f9030] x[[b:bdeb4f9030]?[/b:bdeb4f9030]];
[b:bdeb4f9030]end;[/b:bdeb4f9030]
Minhas dúvidas são estas, apenas quero saber se tem como uma variável receber um determinado valor de um Set.
Desde já agradeço.
Cirolaman
Cirolaman
Curtir tópico
+ 0Posts
25/01/2004
Beppe
type TByteSet = set of Byte; function ByteSetToString(const Bits: TByteSet): String; var I: Integer; begin with TStringStream.Create() do try WriteString(´[´); I := 0; repeat while (I <= 255) and not (I in Bits) do Inc(I); if I > 255 then Exit; if Size > 1 then WriteString(´, ´); WriteString(IntToStr(I)); if (I < 255) and (Succ(I) in Bits) then begin WriteString(IntToStr(I)); while (I <= 255) and (I in Bits) do Inc(I); WriteString(IntToStr(Pred(I))); end; until False; WriteString(´]´); finally Result := DataString; Free; end; end;
Não testei, fiz agora. Então diz se funcionar, ok?
Gostei + 0
25/01/2004
Aroldo Zanela
Se eu entendi o que você quer, então é melhor utilizar um Array ao invés de conjunto.
Var X: array[0..5] of Integer; A: String; begin X[1] := 255; A := intToStr(x[1]); ShowMessage(A); // Retorna 255 end;
Gostei + 0
26/01/2004
Cirolaman
Valeu. Mas não funcionou, quando rodo a aplicação da pau e trava.
Cirolaman.
Gostei + 0
26/01/2004
Beppe
type TByteSet = set of Byte; function ByteSetToString(const Bits: TByteSet): String; var I: Integer; begin with TStringStream.Create(´´) do try WriteString(´[´); I := 0; repeat while (I <= 255) and not (I in Bits) do Inc(I); if I > 255 then Break; if Size > 1 then WriteString(´, ´); WriteString(IntToStr(I)); if (I < 255) and (Succ(I) in Bits) then begin WriteString(´..´); while (I <= 255) and (I in Bits) do Inc(I); WriteString(IntToStr(Pred(I))); end else Inc(I); until False; WriteString(´]´); finally Result := DataString; Free; end; end;
Caption := ByteSetToString([0, 3..8, 10..12, 14]);
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)