Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2016-07

Sven commit (r34087) breaks casting an object to an interface

9 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Maciej Izak

Hi,

change in mentioned FPC trunk r34087 totally breaks sparta dockedformeditor package (and probably many other things) see:

http://forum.lazarus.freepascal.org/index.php/topic,27211.msg216064.html#msg216064 http://bugs.freepascal.org/view.php?id=30377

please revert mentioned commit (what is sense for such change?).

For example problem exist in sparta_MainIDE.pas module:

=== code begin ===
constructor TDesignFormData.Create(AForm: TCustomForm);
begin
  FForm := AForm as IDesignedForm; // won't work anymore. FForm is an
interface
=== code end ===
Best regards, Maciej Izak

Reply by email

Michael Van Canneyt
to Maciej Izak
Maciej Izak wrote 9 lines
Hi, change in mentioned FPC trunk r34087 totally breaks sparta dockedformeditor package (and probably many other things) see: http://forum.lazarus.freepascal.org/index.php/topic,27211.msg216064.html#msg216064 http://bugs.freepascal.org/view.php?id=30377 please revert mentioned commit (what is sense for such change?).

Presumably, Sven has a reason for this change ?

For example, dynamic packages support may necessitate such a change. (just a wild guess)

If the change is needed, the right approach is to fix the bug that this change causes.

Michael.

Reply by email

Juha Manninen
to Maciej Izak: change in mentioned FPC trunk r34087 totally breaks sparta dockedformeditor package (and…
Maciej Izak wrote
constructor TDesignFormData.Create(AForm: TCustomForm); begin FForm := AForm as IDesignedForm; // won't work anymore. FForm is an interface

I have not studied the context of this code but to me it looks suspicious. If such a typecast is needed then something is wrong in the code's design. An obvious idea is to change the AForm's type to IDesignedForm. My intuition says that Sven's commit only revealed some fishy code in sparta dockedformeditor.

Juha

Reply by email

Dimitrios Chr. Ioannidis
to Juha Manninen
Juha Manninen wrote 10 lines
On Fri, Jul 15, 2016 at 12:51 PM, Maciej Izak wrote: > constructor TDesignFormData.Create(AForm: TCustomForm); > begin > FForm := AForm as IDesignedForm; // won't work anymore. FForm is an > interface I have not studied the context of this code but to me it looks suspicious. If such a typecast is needed then something is wrong in the code's design. An obvious idea is to change the AForm's type to IDesignedForm. My intuition says that Sven's commit only revealed some fishy code in sparta dockedformeditor.

AFAIU, unless the AForm ( a TCustomForm descendant which explicitly list IDesignedForm ) doesn't has the IDesignedForm in it's list of supported interfaces, then it's a bug in the compiler, because, AFAIU, the compiler is relying on this in order to implement the as cast, no ?

regards,

Dimitrios Chr. Ioannidis

Reply by email

Juha Manninen
to Dimitrios Chr. Ioannidis
Dimitrios Chr. Ioannidis wrote
AFAIU, unless the AForm ( a TCustomForm descendant which explicitly list IDesignedForm ) doesn't has the IDesignedForm in it's list of supported interfaces, then it's a bug in the compiler, because, AFAIU, the compiler is relying on this in order to implement the as cast, no ?

Ok, true. Technically the compiler should accept such a cast.

Code design is another issue which should not be mixed here, although I still think there is something fishy in that specific use case. It could be implemented differently.

Juha

Reply by email

Dimitrios Chr. Ioannidis
to Maciej Izak: change in mentioned FPC trunk r34087 totally breaks sparta dockedformeditor package (and…
Maciej Izak wrote 18 lines
Hi, change in mentioned FPC trunk r34087 totally breaks sparta dockedformeditor package (and probably many other things) see: http://forum.lazarus.freepascal.org/index.php/topic,27211.msg216064.html#msg216064 http://bugs.freepascal.org/view.php?id=30377 please revert mentioned commit (what is sense for such change?). For example problem exist in sparta_MainIDE.pas module: === code begin === constructor TDesignFormData.Create(AForm: TCustomForm); begin FForm := AForm as IDesignedForm; // won't work anymore. FForm is an interface === code end ===

Just looked in the sources a little bit, and I saw that you use interface inheritance.

Never used that and searching on the net found the following http://stackoverflow.com/questions/14931940/casting-object-to-interface-type-with-no-tinterfacedobject-as-base-class.

The change is for Delphi compatibility maybe ?

Anyway, this is out of my league ....

regards,

Dimitrios Chr. Ioannidis

Reply by email

Maciej Izak
to Juha Manninen: On Fri, Jul 15, 2016 at 2:01 PM, Dimitrios Chr. Ioannidis Ok, true. Technically the…

2016-07-15 13:10 GMT+02:00 Juha Manninen :

Code design is another issue which should not be mixed here, although I still think there is something fishy in that specific use case. It could be implemented differently.

Change for the AForm's type to IDesignedForm is impossible in mentioned context. IDesignedForm means not only "TForm" but is used also to handle forms for TFrame and TDataModule. IDesignedForm is way to unify usage of TForm (which directly exist as form) and "form containers" for TFrame/TDataModule. Nothing wrong with that. Normal code -,- .

Best regards, Maciej Izak

Reply by email

Maciej Izak
to Michael Van Canneyt: Presumably, Sven has a reason for this change ? For example, dynamic packages support may…

2016-07-15 12:18 GMT+02:00 Michael Van Canneyt :

If the change is needed, the right approach is to fix the bug that this change causes.

Fixed in Lazarus trunk r52691.
That was long standing Lazarus bug in JITForms (vmtIntfTable slot was equal 0). It was correct before FPC r34087 because was used FPC_EMPTYINTF instead of nil...

Best regards, Maciej Izak

Reply by email

Juha Manninen
to Maciej Izak: 2016-07-15 13:10 GMT+02:00 Juha Manninen : Change for the AForm's type to IDesignedForm…
Maciej Izak wrote 5 lines
Change for the AForm's type to IDesignedForm is impossible in mentioned context. IDesignedForm means not only "TForm" but is used also to handle forms for TFrame and TDataModule. IDesignedForm is way to unify usage of TForm (which directly exist as form) and "form containers" for TFrame/TDataModule. Nothing wrong with that. Normal code -,- .

Ok, I believe this one is a difficult case because TForm, TFrame etc. don't have those interfaces. You have to stich them in afterwards somehow.

I myself learned that design with interfaces requires to turn all params and APIs to use interfaces.
It is not easy always.

Juha

Reply by email