I started using a lot of generics but now I find it harder and harder to debug, to know which array is actually begin worked on. See example:
Type
TData = record
DataID:integer;
DataName:string;
end;
var DataArr1,DataArr2,DataArr3:TArray<TData>;
procedure WorkOnData(Data:TArray<TData>);
begin
if Data = DataArr1 then // <-- PARKING HERE ON DEBUG I CAN SEE ARRAY DATA, BUT NOT WHICH ARRAY IT IS
ProcessA(DataArr1)
else if Data = DataArr2 then
ProcessB(DataArr2)
else if Data = DataArr3 then
ProcessC(DataArr3);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Sender = Button1 then
WorkOnData(DataArr1)
else if Sender = Button2 then
WorkOnData(DataArr2)
else if Sender = Button3 then
WorkOnData(DataArr3);
end;
So, I can identify the array by comparison to get True/False:
Data = DataArr1
but, this doesn't give me info which array it is, before the comparison. So, I would need to put breakpoints after each comparison to know which one is True.
These obviously don't work:
Data.Name
TArray<Data>.Name
Is there any other way to know which array has been passed that I can see in debugger (Watch)?
Answer/Solution:
For anybody who faces the same problem, question: As Remy says in accepted answer that what I would like to achieve, is not possible. OK, now the quick workaround is to put the comparison (Data = DataArr1
) into Watch and see which one resolves to True. Not best, but still usable as now we can see which array is actually being used.
There are no variable names once the code gets compiled. When you debug WorkOnData()
, the only variable name it can display is Data
, and there is no way for the debugger to know what Data
is pointing at without evaluating an expression that you provide. So no, what you are asking for is basically not possible.
What you would likely have to do is wrap your array inside of another record
that has a Name
string field, and then pass that record around as needed. When you inspect it in the debugger, you would see its Name
value.