Difference between revisions of "Class constants"

From Lazarus wiki
Jump to navigationJump to search
m (syntaxhighlight, update link to documentation)
Line 1: Line 1:
FP supports typed class constants, if the compiler-switch
+
FP supports typed class constants, if the compiler-switch <syntaxhighlight lang="pascal" enclose="none">{$static on}</syntaxhighlight> is set.
<syntaxhighlight lang="pascal">
 
{$static on}
 
</syntaxhighlight>
 
is set.
 
 
There are no untyped class constants.
 
There are no untyped class constants.
  
<syntaxhighlight lang="pascal">
+
<syntaxhighlight lang="pascal" highlight="5,9-10">
type
+
type
TCars = class(TVehicles)
+
TCars = class(TVehicles)
private
+
private
public
+
public
wheelcount: integer: static;
+
wheelcount: integer: static;
end;
+
end;
+
 
begin
+
begin
TCars.wheelcount := 4;
+
TCars.wheelcount := 4;
(* further assignments are forbidden *)
+
// further assignments are forbidden
end.
+
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Weblinks ==
 
== Weblinks ==
* [http://www.freepascal.org/docs-html/ref/refse28.html#x64-710005.3 “Static fields”] in FPC-doc
+
* [https://www.freepascal.org/docs-html/ref/refse30.html “Static fields”] in FPC-doc
  
 
[[Category:FPC]]
 
[[Category:FPC]]
 
[[Category:Constants]]
 
[[Category:Constants]]

Revision as of 18:19, 11 February 2018

FP supports typed class constants, if the compiler-switch {$static on} is set. There are no untyped class constants.

type
	TCars = class(TVehicles)
		private
		public
			wheelcount: integer: static;
	end;

begin
	TCars.wheelcount := 4;
	// further assignments are forbidden
end.

Weblinks