Problem with visibility of namespace level constants and methodslar

I am having a weird problem with namespace level constants and methods compiled into a library. The attached projects exhibit my trouble.

mylibrary/resources.pas declares a record type, a constant, and two methods, all at namespace level (i.e. not inside a class). They are all visible to the program when its project includes resources.pas directly (see myproblem_good) .

But when referencing resources.pas compiled into a library, the record type is visible, but not the constant (see myproblem_bad2) or the methods (see myproblem_bad1).

Prepending public to the constant or method declarations in resources.pas prevents the library from being built at all.

Problem.zip (8.7 KB)

That is as designed. the default visibility for globals is “assembly”, unless they are marked as public. There’s also a global switch in Projects Settings for legal compatibility to treat all globals as public by default.

Can you give me a simple test case that show this error?

thanx,
marc

Setting DefaultGlobalsToPublic to True in the library project solved my problem nicely.

Attached are projects illustrating that public const and public function globals don’t compile.

Problem2.zip (8.0 KB)

Ah yes. this is not C# ;). the proper syntax is

  function GetDesignator1(prompt : String) : Designator; public;

and not

  public function GetDesignator1(prompt : String) : Designator;

:slight_smile:

I got caught by the Principle of Least Surprise. We do public class and public record so I expected public const and public function.

Good point, that is a bit inconsistent indeed – but in line with other directives (say abstract) on classes vs methods :slight_smile: