4
votes

I am upgrading some legacy 3rd party components from Delphi 6 source up to XE2.

The 3rd party source has nested class function within a class procedure. Mock up exact working copy which will fail:

type
  TMyClass1 = class
  public
    class procedure DoSomething;
  end;

{ TMyClass1 }

class procedure TMyClass1.DoSomething;
  class function DoSomethingelse: boolean;
  begin
    result := false;
  end;
begin

end;

trying to compile this gives an error about doSomethingelse being an undeclared identifier. Now I can (presumably) resolve this by pulling the nested function out to the same level, but is there a compiler option that I can set to prevent this? Is this something which has recently changed? Has anyone else come across this issue?

Thanks

1
Perhaps nested function should not have "class" word next to it. If you ant to pull it up - pull it with "class" keyword and add to private section. - Kromster
Some of the 3rd party code in my codebase hit this issue when I moved to XE2. Best solution is to remove the class on the inner. I bet this change is at XE2 and the code above works for all earlier versions. - David Heffernan
@DavidHeffernan this code fails in Delphi XE too, so the change was made in some version between Delphi 2007 and XE. - RRUZ
@RRUZ I encountered the issue when moving from 2010 to XE2 so I guess it was XE then. I assumed XE2 since that was where the more major upheaval took place. - David Heffernan

1 Answers

6
votes

In order to compile your code in XE2 just remove the class Keyword of the DoSomethingelse definition, even if this code compile in older versions of delphi (I tested your code in Delphi 5, 7 and 2007) I don't see the point (or difference) of declare a embedded (inner) procedure or function with the class keyword.