|
|
|
Why are you using var parameters, when you're not modifying their values? You should be using untyped const parameters instead. That would be more intention-revealing, and it would also cause the compiler to give you a warning if you pass in an uninitialized variable.
(P.S. Your commenting system is horribly broken if JavaScript isn't enabled... the comments don't get posted, but you can't re-post the same comment after turning JavaScript on (it complains about a duplicate comment). You might want to fix that.)
Joe White |
Homepage |
10.17.07 - 3:30 pm | #
|
|
Thanks, Joe, for your comment.
I fully agree with you. I've fixed the declarations to const.
Sorry about the javascript problem. I'm using Haloscan for comments. I'll try to find a solution.
TOndrej |
Homepage |
10.17.07 - 4:21 pm | #
|
|
How did you declared the TIntegerSet type?
Ramsees |
10.17.07 - 4:36 pm | #
|
|
Hi Ramsees,
TIntegerSet is declared in SysUtils as follows:
type
TIntegerSet = set of 0..SizeOf(Integer) * 8 - 1;
Cheers.
TOndrej |
Homepage |
10.17.07 - 4:40 pm | #
|
|
Reply ti my self:
It is a Delphi 2007 data type, Im using Delphi 7.
Ramsees |
10.17.07 - 4:43 pm | #
|
|
Oh waith, is in Delphi 7 too but is not documented, thx.
Ramsees |
10.17.07 - 4:44 pm | #
|
|
No, Delphi 7 also has TIntegerSet in SysUtils.
TOndrej |
Homepage |
10.17.07 - 4:45 pm | #
|
|
Yup. No problem. 
TOndrej |
Homepage |
10.17.07 - 4:46 pm | #
|
|
I've fixed the uses clause too, just in case Thanks for your comments.
TOndrej |
Homepage |
10.17.07 - 4:49 pm | #
|
|
Hi,
Shouldn't this return a LongWord or Cardinal rather than an integer?
function GetOrdValue(Info: PTypeInfo; var SetParam): Integer;
begin
Result := 0;
case GetTypeData(Info)^.OrdType of
otSByte, otUByte:
Result := Byte(SetParam);
otSWord, otUWord:
Result := Word(SetParam);
otSLong, otULong:
Result := Integer(SetParam);
end;
end;
twm
Thomas Mueller |
Homepage |
10.17.07 - 5:16 pm | #
|
|
Hi Thomas,
strictly speaking, yes, all these routines should probably use unsigned 32-bit integers. But if you look at TypInfo unit (and VCL sources in general), they also use Integer and Longint a lot where Cardinal or Longword would seem more appropriate.
I know, that's no excuse for the perfectionists/purists out there 
Of course, you're welcome to change the code as you see fit!
Cheers!
TOndrej |
Homepage |
10.17.07 - 5:43 pm | #
|
|
Loved to see something like that for .NET as well 
Holger Flick |
10.19.07 - 3:44 pm | #
|
|
Hi Holger,
I think I it's there already in .NET:
// set to string
A := [alClient, alLeft, alTop];
S := GetSetNames(TypeOf(TAlignSet), Convert.ToInt32(A as TObject), True);
ShowMessage(S);
// string to set
A := System.Enum.ToObject(TypeOf(TAlignSet), GetSetValue(TypeOf(TAlignSet), S)) as TAlignSet;
well, it would be nice to use GetSetObject directly:
A := GetSetObject(TypeOf(TAlignSet), S) as TAlignSet;
unfortunately, GetSetObject is buried in TypInfo's implementation - not exposed in its interface - so you can either copy it out to another unit or use GetSetValue and Enum.ToObject.
Cheers
TOndrej |
Homepage |
10.19.07 - 4:51 pm | #
|
|
How does StringToSet cope with sets which have more than 32 members? It returns Integer, which has 32 bits available for flagging of individual members, set on the other hand can have up to 256 members, i.e. 8 integers.
Boris B. |
01.29.08 - 2:36 pm | #
|
|
Hi Boris,
I've just checked and it doesn't.
These functions are simply modified versions of SetToString, StringToSet functions from TypInfo unit.
However, the compiler only allows published type information for sets with max. 32 elements, for larger sets you get compiler error "E2187: Size of published set is >4 bytes".
So these functions simply don't work for sets larger than 32 elements.
Thanks for your comment. I'll have a look at this and see if I can find a workaround.
HTH
TOndrej |
Homepage |
01.29.08 - 3:27 pm | #
|
|
Commenting by HaloScan
|