I am a .NET developer and very beginner with Delphi.
I want to create a static class and use the properties like this
MyVariable := MyStaticClass.MyProperty;
I don't know how to do that.
Use Class Properties for this;
type
TMyClass = class
strict private
class var // Note fields must be declared as class fields
FRed: Integer;
FGreen: Integer;
FBlue: Integer;
public // ends the class var block
class property Red: Integer read FRed write FRed;
class property Green: Integer read FGreen write FGreen;
class property Blue: Integer read FBlue write FBlue;
end
In this example, properties named Red, Green and Blue can be used without an object reference. For document; Class Properties
To declare a readonly class (static) property;
TMyClass = class
private
const FRedValue:Integer = 10;
public
class property Red: Integer read FRedValue;
end;
To use this;
aColorVariable := TMyClass.Red;
type keywords in one unit!Tips : Unit somhow equals to Class on .NET Finally i resolve my problem by add those properties to my unit like below :
create a unit by right click on the solution name and add > unit
declare a const like below :
const myPropertyName:Integer = 0;
add it to your form who you want to use it by
uses YOUR_UNIT_NAME;
After
interface
section on the form