Gravatar 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.)


Gravatar 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.


Gravatar How did you declared the TIntegerSet type?


Gravatar Hi Ramsees,

TIntegerSet is declared in SysUtils as follows:

type
TIntegerSet = set of 0..SizeOf(Integer) * 8 - 1;

Cheers.


Gravatar Reply ti my self:

It is a Delphi 2007 data type, Im using Delphi 7.


Gravatar Oh waith, is in Delphi 7 too but is not documented, thx.


Gravatar No, Delphi 7 also has TIntegerSet in SysUtils.


Gravatar Yup. No problem.


Gravatar I've fixed the uses clause too, just in case Thanks for your comments.


Gravatar 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


Gravatar 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!


Gravatar Loved to see something like that for .NET as well


Gravatar 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


Gravatar 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.


Gravatar 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




Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan