Reputation: 988
I was wondering if there was a way I can make a set of records in pascal. I am looking all over the internet and believe this is impossible.
type
TRecord = record
StrField: string;
IntField: Integer;
end;
TSetOfRecord = set of TRecord;
Upvotes: 5
Views: 730
Reputation: 253
'Set of records' doesn't make sense. I guess you mean 'collection of records'. If that's the case, you can implement it in more ways than one.
The one I'd recommend would be to use 'open arrays' (not the same as 'dynamic arrays').
You'd need to write a couple of your own routines, one being this:
function RecordInCollection(const ARecord: TYourRecord; const ACollection: array of TYourRecord): Boolean;
var
Index1: Integer;
begin
Result := False;
for Index1 := Low(ACollection) to High(ACollection) do begin
Result := (ACollection[Index1].StrField = ARecord.StrField) and (ACollection[Index1].IntField = ARecord.IntField);
if Result then Exit;
end;
end;
and call it like this:
RecordInCollection(Record1, [Record2, Record3, Record4])
or you could use pre-declared constant arrays instead of [Record2, Record3, Record4].
Upvotes: 1
Reputation: 20320
Yep that's impossible set members have to be an ordinal type. As far as I remember you can only have have a limited number of members as well, 255 rings a bell.
Seems to be way more combinations than that in your record, though it's not clear what defines uniqueness for a member.
Upvotes: 6