Compiler error message "Global members not allowed"

Hello,

I am converting a BDS 2006 .Net windows service application to Delphi Prism.

When compiling the code I the message:  "Global members not allowed" for the declaration : "function GetDateFromDefault"

How should I solve this.  This unit contains a function (GetDateFromDefault) that is used by many units.

unit uDateDefaults;
interface
// This function will convert the default date value into an actual date
function GetDateFromDefault( const pDefault : string ; var ActualDate : DateTime ) : boolean ;
 
implementation
uses uDateUtils ;
 
function GetDateFromDefault( const pDefault : string ; var ActualDate : DateTime ) : boolean ;
  // This function will convert the default date value into an actual date
  var Default : string ;

Open in new window

soozhAsked:
Who is Participating?
 
soozhConnect With a Mentor Author Commented:
The solution to this is to either "allow globals" in the project options... or to put everything in a class.  

I choose the project option and everything worked just fine.
0
 
developmentguruPresidentCommented:
I ran into something similar.  I declared the global function as a public class function and embedded it into a class.  This makes the calling of the function a bit more clumsy, but you have to remember that Oxygene is truer to .NET than Delphi was.  Global functions are not allowed.

I used this technique to create a singleton object by returning a class for global use. If the class is not created it creates it.  Either way it returns it.

    class method Rights : UserRights;

you would need to include the namespace you use in the uses clause and refer to your method as ClassName.GetDateFromDefault

Let me know if you need more.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.