I have defined a TCGTable record type with the following structure:
type
TCGTable = record
x : array [1 .. MAX_POINTS] of Single;
y : array [1 .. MAX_POINTS] of Single;
end;
I have declared a TCGTable variable CGTable.
The variable CGTable is assigned a particular constant TCGTable record value if that record meets several runtime conditions.
If no constant TCGTable record meets these conditions, CGTable should be undefined.
Is there a Delphi 2010 built-in value I can assign to CGTable to indicate that it is undefined? I have tried using the values nil and null, but both of these seem to be valid only for pointer or variant types. The source will not compile with these values assigned to CGTable.
I would like to inspect the variable CGTable to determine its validity instead of, for example, maintaining some additional boolean validity flag.
The only workarounds I can determine are:
a) Change the type of CGTable to a TCGTable pointer (CGTable : ^TCGTable;), which would then allow me to compare CGTable to the nil value.
b) Define some constant TCGTable record to act as an “invalid” record. I would then compare CGTable against this “invalid” record.
Any suggestions on how to approach this? Thanks
You have a record containing a static array. This particular record has a size equal to
ElementCount*SizeOf(Element).Judging by the the fact that your array is sized with a
MAX_POINTSconstant it looks like you have a variable number of points in the array. I think I would be inclined to switch to dynamic arrays like this:Now if you have a variable,
a: TSinglePointArray, then a value ofnilindicates that it is empty or nil. You can query for the length of the array withLength(a). You can resize the array withSetLength(a, NewLength).