View Issue Details

IDProjectCategoryView StatusLast Update
0015140FPCCompilerpublic2019-12-06 08:11
ReporterAnton Kavalenka Assigned To 
Status newResolutionopen 
Platformx86_64OSDebian GNU/Linux 
Product Version2.5.1 
Summary0015140: Compiler allows casting Method of object to class reference
DescriptionAttached program compiles with latest FPC but should NOT.
And obviously crashes when run.

Delphi does not compile attached code
 Error: Not enough actual parameters
Steps To ReproduceCompile and run attached project
TagsNo tags attached.
Fixed in Revision
Attached Files


2009-11-19 15:59


project1.dpr (713 bytes)

Sergei Gorelkin

2011-03-08 14:41

developer   ~0046509

Note that this issue is specific to {$mode delphi} only; in objfpc mode the compiler behaves as expected.

Mark Z

2011-03-24 06:15

reporter   ~0046773

Last edited: 2011-03-24 07:01

Looks to me the method ms.ReadComponent isn't being cast; the result of the method call, which is a TComponent when successful, is being cast. I suspect the compile succeeds in objfpc mode because a parameter default of nil is used for the Instance argument, since it isn't specified as something else. In either mode, with Instance specified, this should compile. The error more is, if the program bombs at runtime, that for some reason the component as written isn't being properly read back with the nil Instance passed and that's why the cast fails.

To try and typecast the actual method I believe you'd have to specify TMemoryStream.ReadComponent instead. That should bomb the compiler whatever mode it's in.

Anton Kavalenka

2013-03-07 09:32

reporter   ~0066084

Problem is even worse:

Try to guess - is it calling of ms.ReadComponent or casting of @TMemoryStream.ReadComponent


Sven Barth

2013-03-07 14:06

manager   ~0066089

If you use "()" the compiler DOES call the method. So in this case you are casting the result of "ms.ReadComponent".


Anton Kavalenka

2013-03-07 17:12

reporter   ~0066095

Last edited: 2013-03-07 20:03

View 2 revisions

There is no method TStream.ReadComponent()
there is only TStream.ReadComponent(AnInstance)

The program should not be compiled at all.

Sven Barth

2013-03-07 21:46

manager   ~0066102

Ok, in that case you are right.


Anton Kavalenka

2019-12-06 08:09

reporter   ~0119653

Last edited: 2019-12-06 08:11

View 2 revisions

Is not this issue can be solve in expression parser like 0036397

Issue History

Date Modified Username Field Change
2009-11-19 15:59 Anton Kavalenka New Issue
2009-11-19 15:59 Anton Kavalenka File Added: project1.dpr
2011-03-08 14:41 Sergei Gorelkin Note Added: 0046509
2011-03-24 06:15 Mark Z Note Added: 0046773
2011-03-24 06:47 Mark Z Note Edited: 0046773
2011-03-24 07:01 Mark Z Note Edited: 0046773
2013-03-07 09:32 Anton Kavalenka Note Added: 0066084
2013-03-07 14:06 Sven Barth Note Added: 0066089
2013-03-07 17:12 Anton Kavalenka Note Added: 0066095
2013-03-07 20:03 Anton Kavalenka Note Edited: 0066095 View Revisions
2013-03-07 21:46 Sven Barth Note Added: 0066102
2019-12-06 08:09 Anton Kavalenka Note Added: 0119653
2019-12-06 08:11 Anton Kavalenka Note Edited: 0119653 View Revisions