3

Following is the code in which I try to declare class variable:

  type TMyClass = class

  private
    class function ABC(myID : integer): string;
  public
    class var s: String;
    class function XYZ: string;
  end;

I am getting error: PROCEDURE or FUNCTION expected. Is there any change in syntax of class variable in Delphi 7?

2 Answers 2

8

Delphi 7 didn't support class variables. You'll have to find another way of solving your problem. An easy fix is probably just to make it be a global variable of the enclosing unit instead.

Sign up to request clarification or add additional context in comments.

5 Comments

Note that there have been at least 10 Delphi releases after Delphi 7 that support class variables.
okay, thanks Rob. One thing I wanted to ask. I know its not related to question but if you can answer. Can I download trial version of Delphi 2006 from anywhere just for testing some code? I know Delphi 2006 supports class variables.
No, Embarcadero does not offer "trial" versions of software that isn't sold anymore. What would the trial be for? Even if you decided you liked it, you wouldn't be able to buy it. Delphi 2006 has been obsolete for eight years. There's no point in upgrading halfway.
What a strange down vote, there's a +1 for the correct answer
@Meraqp Why not download the trial for XE8, the latest version? It is nine versions later than 2006, and much better.
-2

Actually, Delphi-6 supports class variables. For example, you can do this:

var CV: TClass;

CV:=TCheckBox;

if CV=TCheckBox then ...;

1 Comment

No, the questions wasn't about a variable that refers to a class, i.e. a reflection variable. The question was about the field s being created only once for every instance of the class, the equivalent of static in C++ and Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.