Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set of records in pascal

Tags:

pascal

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;         
like image 562
George Host Avatar asked Feb 15 '13 23:02

George Host


2 Answers

'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].

like image 43
Adem Avatar answered Oct 19 '22 12:10

Adem


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.

like image 52
Tony Hopkinson Avatar answered Oct 19 '22 12:10

Tony Hopkinson