# Cannot call Interface methods and cannot overtype interface back to class instance

**URL:** https://talk.remobjects.com/t/cannot-call-interface-methods-and-cannot-overtype-interface-back-to-class-instance/7559
**Category:** Pascal Script
**Tags:** delphi
**Created:** [November 23, 2015, 4:04pm UTC](https://talk.remobjects.com/t/cannot-call-interface-methods-and-cannot-overtype-interface-back-to-class-instance/7559 "2015-11-23T16:04:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jakub\_Klos](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@Jakub\_Klos](https://talk.remobjects.com/u/Jakub_Klos)
#### Post date: [November 23, 2015, 4:04pm UTC](https://talk.remobjects.com/t/cannot-call-interface-methods-and-cannot-overtype-interface-back-to-class-instance/7559/1 "2015-11-23T16:04:38Z")

</div>

Hello  
we have come accross 2 problems with interfaces. Since Pascal Script is supposed to fully support interfaces I am writing this ticket. We have tested it both in Delphi XE2 and FPC 2.6.4

This is the definition in the pascal program. Nothing special here.

type  
IMyInterface = Interface(IUnknown)  
[’{8B7D2D7D-567D-46F4-A294-A52C9F1F4EAF}’]  
procedure writeoutput(a: ansistring);  
end;

TMyClass = class(TRetainableObject, IMyInterface)  
public  
procedure writeoutput(a: ansistring);  
end;

Both the class methods and interface with methods is registered in the compiler and runtime PS classes.

What works is:

- passing an interface back to the pascal program

What does not work:

1. calling interface methods

pascal script:

var  
m: tmyclass;  
i: imyinterface;  
begin  
m := tmyclass.create;  
i := m;  
i.writeoutput(‘1’);  
end.

This results in an PS compiler error (assign expected on the line of “i.writeoutput…”).  
The same code works in Delphi or FPC directly of course

1. overtyping interface to class instance

pascal script:

var  
m: tmyclass;  
i: imyinterface;  
begin  
m := tmyclass.create;  
i := m;  
m := i as tmyclass;  
m.writeoutput(‘aaaa’);  
end.

This does not fire any runtime or compilation error but PS exists / stops executing anything after the line “m := i as tmyclass;”. Simply anything that follows is never executed.  
The same code works in Delphi or FPC…

We believe these to be bugs.  
Please, let me know if we can assist any more

Thank you very much  
Regards,  
Jakub

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [November 23, 2015, 6:45pm UTC](https://talk.remobjects.com/t/cannot-call-interface-methods-and-cannot-overtype-interface-back-to-class-instance/7559/2 "2015-11-23T18:45:03Z")

</div>

> [@Jakub\_Klos](#):
>
> Hellowe have come accross 2 problems with interfaces. Since Pascal Script is supposed to fully support interfaces I am writing this ticket. We have tested it both in Delphi XE2 and FPC 2.6.4
> 
> This is the definition in the pascal program. Nothing special here.
> 
> type IMyInterface = Interface(IUnknown) [‘{8B7D2D7D-567D-46F4-A294-A52C9F1F4EAF}’] procedure writeoutput(a: ansistring); end;
> 
> TMyClass = class(TRetainableObject, IMyInterface) public procedure writeoutput(a: ansistring); end;
> 
> Both the class methods and interface with methods is registered in the compiler and runtime PS classes.
> 
> What works is:- passing an interface back to the pascal program
> 
> What does not work:1. calling interface methods
> 
> pascal script:
> 
> var m: tmyclass; i: imyinterface; begin m := tmyclass.create; i := m; i.writeoutput(‘1’); end.
> 
> This results in an PS compiler error (assign expected on the line of “i.writeoutput…”).The same code works in Delphi or FPC directly of course

Logged here:

> <https://github.com/remobjects/pascalscript/issues/121>
>
> logged from http://talk.remobjects.com/t/cannot-call-interface-methods-and-canno…t-overtype-interface-back-to-class-instance/7559 ( Jakub\_Klos3h )
> Hello
> we have come accross 2 problems with interfaces. Since Pascal Script is supposed to fully support interfaces I am writing this ticket. We have tested it both in Delphi XE2 and FPC 2.6.4
> 
> This is the definition in the pascal program. Nothing special here.
> 
> \`\`\`
> type
> IMyInterface = Interface(IUnknown)
> \['{8B7D2D7D-567D-46F4-A294-A52C9F1F4EAF}'\]
> procedure writeoutput(a: ansistring);
> end;
> 
> TMyClass = class(TRetainableObject, IMyInterface)
> public
> procedure writeoutput(a: ansistring);
> end;
> \`\`\`
> 
> Both the class methods and interface with methods is registered in the compiler and runtime PS classes.
> 
> What works is:
> \- passing an interface back to the pascal program
> 
> What does not work:
> 1. calling interface methods
> 
> pascal script:
> 
> \`\`\`
> var
> m: tmyclass;
> i: imyinterface;
> begin
> m := tmyclass.create;
> i := m;
> i.writeoutput('1');
> end.
> \`\`\`
> 
> This results in an PS compiler error (assign expected on the line of "i.writeoutput...").
> The same code works in Delphi or FPC directly of course

as for the second issue, that’s not supported by most Delphiversions and older FreePascal. But patches for this are welcome of course.
