What does "A type cannot be be used as a standalone statement" error mean?

92 views Asked by At

This is Delphi Prism for .NET. I am running into this error(s), "A type cannot be be used as a standalone statement", and I don't understand or know why. The compiler is pointing at the lines right below var keywords.

method ScriptDlgpas.ExecuteStartup;
var
  sname:string;     <------ error raised here
  slist:ArrayList;  <------ error raised here
begin
  sname := basedir+'system\startup.scr';
  if File.Exists(sname) then
  begin
    slist := new ArrayList;
    ExecuteScript(slist);
  end;
end;

The Google Search isn't helping either.

Thanks in advance.

2

There are 2 answers

0
Carlo Kok On BEST ANSWER

There's probably something above it that doesn't get closed properly.

0
Sebastian P.R. Gingter On

Try inlining the variables (reducing scope is a good thing btw.):

method ScriptDlgpas.ExecuteStartup;
begin
  var sname := basedir + 'system\startup.scr';
  if File.Exists(sname) then
  begin
    var slist := new ArrayList;
    ExecuteScript(slist);
  end;
end;