Compiler error message "Global members not allowed"

Posted on 2009-04-27
Medium Priority
Last Modified: 2013-11-23

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;
// This function will convert the default date value into an actual date
function GetDateFromDefault( const pDefault : string ; var ActualDate : DateTime ) : boolean ;
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

Question by:soozh
LVL 21

Expert Comment

ID: 24242076
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.

Accepted Solution

soozh earned 0 total points
ID: 24258002
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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question