Так не компилируется:
- Код: Выделить всё
{$MODE OBJFPC}
interface
var
f : LongInt;
property
p : LongInt read f;
implementation
end.
Модератор: Модераторы
{$MODE OBJFPC}
interface
var
f : LongInt;
property
p : LongInt read f;
implementation
end.
A global block can declare properties, just as they could be defined in a class.
The difference is that the global property does not need a class instance:
there is only 1 instance of this property. Other than that, a global property
behaves like a class property. The read/write specifiers for the global property
must also be regular procedures, not methods.
The concept of a global property is specific to Free Pascal, and does not exist in Delphi.
The concept of a global property can be used to 'hide' the location of the value, or to
calculate the value on the fly, or to check the values which are written to the property.
interface
function a : LongInt;
property
p : LongInt read a;
implementation
function a : LongInt;
begin
end;
end.
interface
function p : LongInt;
implementation
function p : LongInt;
begin
end;
end.
unit testgpsh;
interface
var
f : LongInt;
function a : LongInt;
procedure b(Value: LongInt);
property
p : LongInt read a write b;
implementation
function a : LongInt;
begin
Exit(f);
end;
procedure b(Value: LongInt);
begin
f := Value;
WriteLn('Переменной F было присвоено значение: ', f);
end;
initialization
f := 0;
end.
uses testgpsh;
begin
p := 10;
end.
Вернуться в Free Pascal Compiler
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 4