* * *

Author Topic: Helper for interface  (Read 3560 times)

soerensen3

  • Full Member
  • ***
  • Posts: 113
Re: Helper for interface
« Reply #15 on: January 06, 2018, 10:17:47 pm »
Direct X uses interfaces to pass for example a device. As far as I know one interface is never mixed with another type of interface but I might be wrong about that. It is merely used as a way of communication between DX and the application. You cannot change the methods of it with inheritance because you only have the interface though. Therefore the helper or the wrapper.
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

Thaddy

  • Hero Member
  • *****
  • Posts: 6099
Re: Helper for interface
« Reply #16 on: January 08, 2018, 10:16:06 am »
Direct X uses interfaces to pass for example a device. As far as I know one interface is never mixed with another type of interface but I might be wrong about that. It is merely used as a way of communication between DX and the application. You cannot change the methods of it with inheritance because you only have the interface though. Therefore the helper or the wrapper.

No, the general case for an interface helper is a single type helper for an interface as opposed to multiple  wrappers for the classes that support it....   :) So it is not
"the helper or the wrapper" but "the helper or the wrappers".
The ratio is that interfaces can be supported by classes that are otherwise completely unrelated.

I am kind of lazy, I prefer the interface helper. Get the point? Otherwise I will provide a simple example why this is the case.

A second ratio is, by application of the above:
If you examine the example that is now solved you will see that there is a parameter with a default value *before* a parameter without a default. Object Pascal does not support this, but with an interface helper we do....And actually in a far more readable way.
Technically it has no impact on the actual interface. It has only impact on the way the interface can be called. The default value somewhere in the middle of the parameter list is solved by the type helper.
Even for any unrelated class that supports the original interface... that contains a default in its definition... That's why it is so powerful.

Side note: I originally disapproved of this feature, but now I am convinced.
« Last Edit: January 08, 2018, 11:36:36 am by Thaddy »
I might not give the answer that you want me to.. Peter Green 1969

PascalDragon

  • Full Member
  • ***
  • Posts: 108
  • Compiler Developer
Re: Helper for interface
« Reply #17 on: January 10, 2018, 11:43:14 am »
So I have added this
Code: Pascal  [Select]
  1.   {$IF FPC_FULLVERSION >= 30101}
  2.      { ID2D1RenderTargetHelper }
  3.      ID2D1RenderTargetHelper =  type helper for ID2D1RenderTarget
  4.          function CreateSolidColorBrush(const color:TD2D1_COLOR_F; out solidColorBrush:ID2D1SolidColorBrush):HRESULT; stdcall; overload;
  5.      end;
  6.      {$ENDIF}  
and added the implementation

Code: Pascal  [Select]
  1. { ID2D1RenderTargetHelper }
  2. {$IF FPC_FULLVERSION >= 30101}
  3. function ID2D1RenderTargetHelper.CreateSolidColorBrush(
  4.   const color: TD2D1_COLOR_F; out solidColorBrush: ID2D1SolidColorBrush
  5.   ): HRESULT; stdcall;
  6. begin
  7.     result:= CreateSolidColorBrush(color, nil, solidColorBrush);
  8.  end;
  9. {$ENDIF}  

Note 1: you don't need to declare the method in the helper as "stdcall"
Note 2: you can declare the method in the helper as "inline" so that the compiler will completely omit the call to the helper's method and directly call the interface's method instead.

Thaddy

  • Hero Member
  • *****
  • Posts: 6099
Re: Helper for interface
« Reply #18 on: January 10, 2018, 12:14:08 pm »
I didn't realize that (Your two remarks) Sven, but anyway he has a good example why it is useful, don't you think? Thanks for implementing it.
I might not give the answer that you want me to.. Peter Green 1969

PascalDragon

  • Full Member
  • ***
  • Posts: 108
  • Compiler Developer
Re: Helper for interface
« Reply #19 on: January 13, 2018, 01:56:49 pm »
I didn't realize that (Your two remarks) Sven, but anyway he has a good example why it is useful, don't you think? Thanks for implementing it.
Definitely. And examples like this are one of the reasons I implemented it. :)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus