我想知道是否有办法在Pascal中创建一组记录。 我在网上搜寻了很多,认为这是不可能的。
type
TRecord = record
StrField: string;
IntField: Integer;
end;
TSetOfRecord = set of TRecord;
我想知道是否有办法在Pascal中创建一组记录。 我在网上搜寻了很多,认为这是不可能的。
type
TRecord = record
StrField: string;
IntField: Integer;
end;
TSetOfRecord = set of TRecord;
是的,这是不可能的,集合成员必须是有序类型。据我所知,您也只能拥有有限的成员数量,255似乎很熟悉。
尽管记录中似乎有更多的组合,但不清楚什么定义了成员的唯一性。
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;
你可以这样调用它:
RecordInCollection(Record1,[Record2,Record3,Record4])
或者你可以使用预先声明的常量数组而不是[Record2,Record3,Record4]。