View Issue Details

IDProjectCategoryView StatusLast Update
0032586FPCRTLpublic2017-10-20 22:05
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0032586: SetOrdProp doesn't raise an exception when trying to set read-only property
DescriptionSetOrdProp 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 Reproduceprogram 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.
TagsNo tags attached.
Fixed in Revision37495
FPCOldBugId
FPCTarget
Attached Files
  • typinfo-1.patch (660 bytes)
    Index: rtl/objpas/typinfo.pp
    ===================================================================
    --- rtl/objpas/typinfo.pp	(revision 37492)
    +++ rtl/objpas/typinfo.pp	(working copy)
    @@ -1509,6 +1509,9 @@
       end;
     end;
     
    +Resourcestring
    +  SErrCannotWriteToProperty = 'Cannot write to property %s.';
    +
     Procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;Value : Int64);
     type
       TSetInt64ProcIndex=procedure(index:longint;i:Int64) of object;
    @@ -1578,6 +1581,8 @@
                   TSetIntegerProc(AMethod)(Value);
               end;
           end;
    +  else
    +    raise EPropertyError.CreateFmt(SErrCannotWriteToProperty, [PropInfo^.Name]);
       end;
     end;
     
    
    typinfo-1.patch (660 bytes)

Activities

Ondrej Pokorny

2017-10-20 13:05

developer  

typinfo-1.patch (660 bytes)
Index: rtl/objpas/typinfo.pp
===================================================================
--- rtl/objpas/typinfo.pp	(revision 37492)
+++ rtl/objpas/typinfo.pp	(working copy)
@@ -1509,6 +1509,9 @@
   end;
 end;
 
+Resourcestring
+  SErrCannotWriteToProperty = 'Cannot write to property %s.';
+
 Procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;Value : Int64);
 type
   TSetInt64ProcIndex=procedure(index:longint;i:Int64) of object;
@@ -1578,6 +1581,8 @@
               TSetIntegerProc(AMethod)(Value);
           end;
       end;
+  else
+    raise EPropertyError.CreateFmt(SErrCannotWriteToProperty, [PropInfo^.Name]);
   end;
 end;
 
typinfo-1.patch (660 bytes)

Michael Van Canneyt

2017-10-20 20:45

administrator   ~0103616

Applied, extended patch so the same behaviour is encountered in all properties.

Ondrej Pokorny

2017-10-20 22:05

developer   ~0103622

Excelent work, Michael. Thank you.

Issue History

Date Modified Username Field Change
2017-10-20 13:05 Ondrej Pokorny New Issue
2017-10-20 13:05 Ondrej Pokorny File Added: typinfo-1.patch
2017-10-20 14:25 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-10-20 14:25 Michael Van Canneyt Status new => assigned
2017-10-20 20:45 Michael Van Canneyt Fixed in Revision => 37495
2017-10-20 20:45 Michael Van Canneyt Note Added: 0103616
2017-10-20 20:45 Michael Van Canneyt Status assigned => resolved
2017-10-20 20:45 Michael Van Canneyt Fixed in Version => 3.1.1
2017-10-20 20:45 Michael Van Canneyt Resolution open => fixed
2017-10-20 20:45 Michael Van Canneyt Target Version => 3.2.0
2017-10-20 22:05 Ondrej Pokorny Note Added: 0103622
2017-10-20 22:05 Ondrej Pokorny Status resolved => closed