E2130 Cannot read a write-only property (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)

The property from which you are attempting to read a value did not specify a 'read' clause, thereby causing it to be a write-only property.


program Produce;

  type
    Base = class
      s : String;

      property Password : String write s;
    end;

  var
    c : Base;
    s : String;

begin
  s := c.Password;
end.

Since c.Password has not specified a read clause, it is not possible to read its value.


program Solve;

  type
    Base = class
      s : String;

      property Password : String read s write s;
    end;

  var
    c : Base;
    s : String;

begin
  s := c.Password;
end.

One easy solution to this problem, if you have source code, would be to add a read clause to the write-only property. But, adding a read clause is not always desirable and could lead to holes in a security system. Consider, for example, a write-only property called 'Password', as in this example: you certainly wouldn't want to casually allow programs using this class to read the stored password. If a property was created as write-only, there is probably a good reason for it and you should reexamine why you need to read this property.