|
Reported by Björn Sahlen; checked by Reinier Sterkenburg
To reproduce, compile and execute the code below.
This is a bug because:
If there is something wrong with this code (which I don't think it is),
the compiler should give an error. Now you will get this message
on the screen at runtime:
Project ... raised exeption class EAccessViolation with message
'Access violation at adress ...'
Under Kylix, the behaviour is slightly different:
On the statement
AObj.Prop:= 3;
in TForm1.FormCreate, a SIGSEGV error occurs, followed by an Access Violation.
A closer look (stepping/tracing) reveals that the program jumps spontaneously
to the PROCEDURE IObj.Proc and that is where the error occurs.
Note: this happens with Optimization Off.
It seems that somehow there is a mixup with the address of the field
(property).
This bug is N/A for Delphi 1 since Delphi 1 does not allow properties in objects.
The code:
unit DelphiErr2U;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
TYPE
IObj= Object
// FieldThatMakesTheTotalFieldSizeGreaterThanFourBytes: Byte;
I: LongInt;
FUNCTION Func: LongInt;
PROCEDURE Proc (X: LongInt);
PROPERTY Prop: LongInt Read Func Write Proc;
END;
FUNCTION IObj.Func: LongInt;
BEGIN
Result:= 5;
END;
PROCEDURE IObj.Proc(X: LongInt);
BEGIN
I:= X + 1;
END;
procedure TForm1.Button1Click(Sender: TObject);
VAR AObj: IObj; Z: LongInt;
begin
AObj.Prop:= 3;
Z:= AObj.Prop;
Caption:= IntToStr(Z);
end; // Access violation when leaving this procedure.
end. |