HomeDelphiDelphi Error – E2130 Cannot read a write-only property

Delphi Error – E2130 Cannot read a write-only property

Delphi Compiler Error

E2130 Cannot read a write-only property

Reason for the Error & Solution

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.

Share:

Leave a Reply

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...