[SOLVED] Access a const from a class
-
hello guys... I have a type
TClassFoo
in which I have a const like thisunit ClassFoo;
interface
uses ClassBase;type TClassFoo = class
public const NUMBER = 100;
end;I have two types
TClassBase
andTClassChild
.TClassFoo
andTClassBase
have references of each other. I want to access the constant fromTClassFoo
inTClassChild
like this..//*************************** Base Class ******************************//
unit ClassBase;interface
type TClassBase = class
end;implmentation
uses ClassFoo // had to put it here..otherwise it raises 'circular reference error'.
var objFoo : TClassFoo;//*************************** Child Class ******************************//
unit ClassChild;interface
type TClassChild = class(TClassBase)
// here I want to access TClassFoo.NUMBER
end;So how can I do that ? Thanks for any input.
This world is going to explode due to international politics, SOON.
-
hello guys... I have a type
TClassFoo
in which I have a const like thisunit ClassFoo;
interface
uses ClassBase;type TClassFoo = class
public const NUMBER = 100;
end;I have two types
TClassBase
andTClassChild
.TClassFoo
andTClassBase
have references of each other. I want to access the constant fromTClassFoo
inTClassChild
like this..//*************************** Base Class ******************************//
unit ClassBase;interface
type TClassBase = class
end;implmentation
uses ClassFoo // had to put it here..otherwise it raises 'circular reference error'.
var objFoo : TClassFoo;//*************************** Child Class ******************************//
unit ClassChild;interface
type TClassChild = class(TClassBase)
// here I want to access TClassFoo.NUMBER
end;So how can I do that ? Thanks for any input.
This world is going to explode due to international politics, SOON.
You could add a static read-only property that returns the constant.
This statement is false.
-
hello guys... I have a type
TClassFoo
in which I have a const like thisunit ClassFoo;
interface
uses ClassBase;type TClassFoo = class
public const NUMBER = 100;
end;I have two types
TClassBase
andTClassChild
.TClassFoo
andTClassBase
have references of each other. I want to access the constant fromTClassFoo
inTClassChild
like this..//*************************** Base Class ******************************//
unit ClassBase;interface
type TClassBase = class
end;implmentation
uses ClassFoo // had to put it here..otherwise it raises 'circular reference error'.
var objFoo : TClassFoo;//*************************** Child Class ******************************//
unit ClassChild;interface
type TClassChild = class(TClassBase)
// here I want to access TClassFoo.NUMBER
end;So how can I do that ? Thanks for any input.
This world is going to explode due to international politics, SOON.
-
smags13 wrote:
TClassFoo.NUMBER
This is exactly what I tried but it did not work. I am using Embercadero Delphi XE2 version. I am new to delphi.
This world is going to explode due to international politics, SOON.
-
smags13 wrote:
TClassFoo.NUMBER
This is exactly what I tried but it did not work. I am using Embercadero Delphi XE2 version. I am new to delphi.
This world is going to explode due to international politics, SOON.
class const is available since Delphi 7 (or Delphi 2009?) (http://edn.embarcadero.com/article/34324[^]), so your compiler is good. What type of error/complain did you get? Did it happen at compilation time or run time? I think what did not work may not relate to class const. You could try a simplified codes where only one class is defined with a class const, and then access it from a different unit, and see if it works, which I think it should.