So, to save myself some time (theoretically, at least), I've written a function:
type
TComponentArray = array of TComponent;
procedure ProgressiveTag(aList: TComponentArray; aBase: Integer = 0);
var
i: Integer;
begin
for i := 0 to Length(aList)-1 do
aList[i].Tag := aBase + i;
end;
(I realise I could just directly hardcode the tags onto the form, but this makes it a bit easier if I need to change things later.)
The intention here is that I can do code like the following:
ProgressiveTag( [TabSheet1, TabSheet2, ...], 1);
ProgressiveTag( [EditBox1, CheckBox1, ...], 0);
However - when I try to build this code, it says:
****.pas(92,83) Error: Incompatible type for arg no. 1: Got "{Array Of Const/Constant Open} Array of TComponent", expected "TComponentArray"
It seems that when the array is all the same type, it tries to interpret the literal as an array of this type. For example, if they're all TTabSheets, it interprets it as "array of TTabSheet" rather than "array of TComponent", despite that TTabSheet is a TComponent descendant. In fact, even if I mix them, or explicitly typecast some or even all elements to TComponent, it still has this issue:
****.pas(91,65) Error: Incompatible type for arg no. 1: Got "{Array Of Const/Constant Open} Array of TComponent", expected "TComponentArray"
If I try to typecast the array literal as a whole, I get this error:
****.pas(91,19) Error: Illegal type conversion: "{Array Of Const/Constant Open} Array of TTabSheet" to "TComponentArray"
If I recall correctly, an array literal can only be specified as a const if it has a fixed size, which these don't? I did think about definining consts rather than putting the array literals inline. Or is this something that will work in FPC / Lazarus and just not in Delphi? (I'm a very recent convert to Lazarus.)
So - what should I be doing here? Or is there simply no quick-and-easy way to do this and I should just do something a bit more manual?
(For the record, this is for an internal-use-only tool that I don't expect anyone but myself will ever use, so it doesn't really matter if it's not the most optimal code - being able to, in the long run, save time writing it is more important.)