SetOrdProp doesn't raise an exception when trying to set read-only property
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
SetOrdProp should raise an exception when trying to set read-only property. Instead, nothing is done - the programmer has no information that the operation is not allowed and didn't succeed.
Delphi raises an AV because it tries to write it regardless of the fact it is read-only.
Patch is attached - a suitable exception is raised (more useful than Delphi's AV).
Steps to reproduce:
program Project1;
{$mode objfpc}{$H+}
uses
SysUtils, Classes, TypInfo;
type
TMyClass = class(TPersistent)
private
fA: Byte;
published
property A: Byte read fA;
end;
var
O: TMyClass;
PI: PPropInfo;
begin
O := TMyClass.Create;
PI := GetPropInfo(O, 'A');
SetOrdProp(O, PI, 1); // << Exception should be raised here
Writeln(O.A);
Readln;
end.
Mantis conversion info:
- Mantis ID: 32586
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 37495 (#3d3bbcfa)
- Target version: 3.2.0