Reputation: 6762
Any ideas why I get this warning in Delphi XE:
[DCC Warning] Form1.pas(250): W1036 Variable '$frame' might not have been initialized
procedure TForm1.Action1Execute(Sender: TObject);
var
Thread: TThread;
begin
...
Thread := TThread.CreateAnonymousThread(
procedure{Anonymos}()
procedure ShowLoading(const Show: Boolean);
begin /// <------------- WARNING IS GIVEN FOR THIS LINE (line number 250)
Thread.Synchronize(Thread,
procedure{Anonymous}()
begin
...
Button1.Enabled := not Show;
...
end
);
end;
var
i: Integer;
begin
ShowLoading(true);
try
Thread.Synchronize(Thread,
procedure{Anonymous}()
begin
... // some UI updates
end
Thread.Synchronize(Thread,
procedure{Anonymous}()
begin
... // some UI updates
end
);
finally
ShowLoading(false);
end;
end
).NameThread('Some Thread Name');
Thread.Start;
end;
I do not have anywhere in my code a variable names frame nor $frame. I am even not sure how $frame with $ sign can be a valid identifier.
Smells like compiler magic to me.
PS: Of course the real life xosw is having other than Form1, Button1, Action1 names.
Upvotes: 3
Views: 601
Reputation: 34899
In XE2 this compiler warning is not there. Anyway, to make your method a bit clearer to the compiler, try this :
procedure TForm1.Action1Execute(Sender : TObject);
var
Thread: TThread;
begin
Thread := TThread.CreateAnonymousThread(
procedure{Anonymos}()
Type
TProcRef = reference to procedure (const Show: Boolean);
var
i: Integer;
ShowLoading : TProcRef;
begin
ShowLoading:=
procedure (const Show: Boolean)
begin
Thread.Synchronize(Thread,
procedure{Anonymous}()
begin
// Button1.Enabled := not Show;
end
);
end;
ShowLoading(true);
... // and so on.
Update : I just checked in XE, this really fixes the compiler warning.
The reference I gave in the comment to the question explains about the warning and frame objects. So I guess that the XE compiler is getting confused about the frame object ShowLoading is creating. And creating an explicit reference fixed the warning.
Update 2 :
Just showing my test for your reference :
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows,Classes, SysUtils;
procedure Action1Execute;
var
Thread: TThread;
begin
Thread := TThread.CreateAnonymousThread(
procedure{Anonymos}()
Type
TProcRef = reference to procedure (const Show: Boolean);
var
i: Integer;
ShowLoading : TProcRef;
begin
ShowLoading:=
procedure (const Show: Boolean)
begin
Thread.Synchronize(Thread,
procedure{Anonymous}()
begin
// Button1.Enabled := not Show;
end
);
end;
ShowLoading(true);
try
Thread.Synchronize( Thread,
procedure{Anonymous}()
begin
// some UI updates
end
);
Thread.Synchronize( Thread,
procedure{Anonymous}()
begin
// some UI updates
end
);
finally
ShowLoading(false);
end;
end
); //.NameThreadForDebugging('Some Thread Name');
Thread.Start;
end;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
Action1Execute;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Upvotes: 3