TMyClass = Class
Public
Constructor Create;
Private
......
Protected
....
end;
But I need to make a Static Variable, I know have to do it in C++, put not
in Delphi/Pascal.
Can Any one help me please.
Søren Hansen Denmark
If you create a global variable you obtain the same effect.
Static methods was created because Java is Object Oriented, but sometimes we need to use a simple function like StrToInt, Sin,
Sqrt... In Delphi we don't need to create a class to implement this kind of procedures or functions.
In Object Pascal you use Object Orientation if you want.
If you need a static variable inside a method or procedure/function, declare the variable as a typed constant.
function NextInt : Integer;
const
staticint : Integer = 0;
begin
Inc(staticint);
Result := staticint;
end;
[]s
Arthur
Søren Ove Hansen <henriett...@mail.tele.dk> escreveu nas notícias de mensagem:93njp4$rg...@bornews.inprise.com...
there are no generic "class constants" in Delphi. But you may declare a
class function that returns the value you need:
TMyClass = class
public
class function MyStaticClassValue : integer;
end;
implementation
class function TMyClass.MyStaticClassValue : integer;
begin
result := 17;
end;
You can now get the value even without having an instance if the class
by e.g.
MyTestVar := TMyClass.MyStaticClassValue;
{MyTestVar now has a value of 17}
Of course you will not be able to assign a different value to this.
Now if you declare a variable in the interface-section of the unit the
class is implemented in, and give your class an extra Set-method the
solution could look like this:
unit Test;
interface
TMyClass = class
public
class function MyClassValue : integer;
class procedure SetMyClassValue(AValue : integer);
end;
implementation
var
MycalssValue : integer;
class function TMyClass.MyClassValue : integer;
begin
result := MyClassValue;
end;
class procedure SetMyCalssValue(AValue : integer);
begin
MyClassValue := AValue;
end;
initaliazation
MyClassValue := 0;
end.
The users of unit Test will only be able to manipulate MyClassValue
through your class-methods, because the variable is only visible within
the implementatio of the unit.
Is this what you've requested?
Bye
Robert
P.S.: And PLEASE, not another discussion about class-varaibles in
genral. Okay?
Søren Ove Hansen <henriett...@mail.tele.dk> wrote in message
news:93njp4$rg...@bornews.inprise.com...