Type Definition Functions
Array and set definitions use few functons for type checking. This function checks if type is zero-based character array:
- Base type must be
Array
- Element type must be
System.Char
- Size must be non zero
- Index base type must be
btInteger
- Index lower limit must be zero
Function TArrayTypeDefinition.IsZeroBasedCharacterArray: Boolean;
begin
IsZeroBasedCharacterArray := False;
If BaseType <> btArray then Exit;
If ElementTypeOffset.TypeOffset <> Char_TypeOffset then Exit;
If PUnitIdentifierData (Ptr (Seg (Self), ElementTypeOffset.UnitIdentifierData))^.UnitSegment <>
SystemUnitSegment then Exit;
If Size < 1 then Exit;
With POrdinalTypeDefinition (PointerFromOffsets (IndexTypeOffset))^ do
begin
If BaseType <> btInteger then Exit;
If LowerLimit <> 0 then Exit;
end;
IsZeroBasedCharacterArray := True
end;
This function checks if type is character array compatible with string:
- Base type must be
Array
- Element base type must be
Char
- Size must be between 1 and 255
Variable Len
returns the actual array size.
Function TArrayTypeDefinition.IsCharacterArrayCompatibleWithString (Var Len: Byte): Boolean;
begin
IsCharacterArrayCompatibleWithString := False;
If BaseType <> btArray then Exit;
If PTypeDefinition (PointerFromOffsets (ElementTypeOffset))^.BaseType <> btChar then Exit;
If Size < 1 then Exit;
If Size > 255 then Exit;
Len := Size;
IsCharacterArrayCompatibleWithString := True;
end;
This function returns set size and offset of the lowest element in set.
Function TSetTypeDefinition.GetSetSizeAndLowestElementDataOffset (Var DataOffset: Byte): Byte;
begin
GetSetSizeAndLowestElementDataOffset := Size;
DataOffset := POrdinalTypeDefinition (PointerFromOffsets (BaseSetTypeOffset))^.LowerLimit shr 3;
end;