![]() The default, however, is to maintain backward compatibility and let you change the value of a typed constant. You can force yourself to follow this good habit by disabling the $J or $WriteableConst compiler directive, which tells Delphi to treat all constants as constants. The term "typed constant" is clearly a misnomer, and at the unit level, you should always use an initialized var declaration instead of a typed constant. Another way to write the same function is as follows:Ĭount: Integer = 0 function Counter: Integer begin Return a unique number each time the function is called.Īt the unit level, a variable retains its value in the same way, so you can declare it as a constant or as a variable. In C and C++, this entity is called a static variable. ![]() You can assign a new value to the "constant," and it keeps that value. When you declare the type of a constant, Delphi sets aside memory for that constant and treats it as a variable. Delphi also supports multithreaded applications by letting you declare variables that have distinct values in each thread of your application. Unlike standard Pascal, Delphi lets you declare the type of a constant, and you can initialize a global variable to a constant value.
0 Comments
Leave a Reply. |