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;
'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].
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With