(Based on comments I have edited the question to focus on the actual code part causing the issue, and added a section at the end)
This is the local variables window in my Delphi 10.3.4 Win32 app, note that lData
is missing:
The breakpoint corresponding to that screenshot is on the if EmptyJSONArray(lData)
line at the end of the next code snippet:
function TLoketAPI.GetOneBatch(AJSONToXML: TJSONToXML; const ASelProps: TSelectionProps; var ABatchCount, AStatusCode: Integer): Boolean;
var
lURL,
lNextID,
lData : String;
lLogHTTP : TLogHTTP;
begin
Result := false;
if FAbort then Exit;
lLogHTTP := TLogHTTP.Create(nil);
Result := false;
if ABatchCount = 0 then
lNextID := ASelProps.GetNextIDValue
else
lNextID := ASelProps.GetSameIDValue;
lURL := StringReplace(ASelProps.URL,'{id}',lNextID,[rfReplaceAll,rfIgnoreCase]);
if ABatchCount <> 0 then
if Pos('?',lURL) = 0 then lURL := lURL + '?pageNumber=' + IntToStr(ABatchCount+1)
else lURL := lURL + '&pageNumber=' + IntToStr(ABatchCount+1);
try
SetHTTPJSONProperties(lLogHTTP);
try
lLogHTTP.Get(lURL);
if FAbort then
Exit;
lData := lLogHTTP.TransferredData;
if FSaveJSON then
begin
lBatchCount := ABatchCount;
TThread.Synchronize(nil,
procedure
begin
if lNextID = '' then
SaveToJSONFile(Format('%s batch (%d)',[ASelProps.TextID,lBatchCount]),lData)
else
SaveToJSONFile(Format('%s (%s) batch (%d)',[ASelProps.TextID,lNextID,lBatchCount]),lData);
end);
end;
if EmptyJSONArray(lData) then
lData
contains valid data returned from the logHTTP
call.
At the breakpoint (or anywhere else in the routine), lData
does not show up in the local variables and cannot be inspected or watched.
The IDE gives:
E2003 Undeclared identifier: 'lData'
This stuff is running in the main thread, optimization is off.
If I comment out the TThread.Synchronize
, lData
can again be inspected/watched.
What is going on here?
(Added) In the comments, Remy and Dalija suggested that anonymous procedure as the reason, and linked this to the Embarcadero issue RSP-22924 Watch shows undeclared identifier for captured local variables (also reported under RSP-21917).
I still don't get it though: RSP-22924
was edited to change its type to Feature. Feature? It looks like a bug to me.
And: (How) can this behavior be prevented? I'd really like to inspect lData
.