Recent

Author Topic: using interface  (Read 1895 times)

Dzandaa

  • Full Member
  • ***
  • Posts: 248
  • From C# to Lazarus
using interface
« on: October 15, 2021, 11:54:49 am »
Hi everybody,

Working with Pascal Lazarus 2.0.12 on Windows Mac and Linux.

I try to translate one of my C# program to Pascal and I'm stuck with interfaces...

My C# code:

Code: C  [Select][+][-]
  1.    public interface INeuronSignal
  2.     {
  3.         double Output { get; set; }
  4.     }
  5.  
  6.     public interface INeuronReceptor
  7.     {
  8.         Dictionary<INeuronSignal, NeuralFactor> Input { get; }
  9.     }
  10.  
  11.     public interface INeuron : INeuronSignal, INeuronReceptor
  12.     {
  13.        // Etc...
  14.     }
  15.  


My Pascal Code:

Code: Pascal  [Select][+][-]
  1. type
  2. INeuronSignal = interface
  3.   function GetOutput:Double;
  4.   procedure SetOutput(AX:Double);
  5.   property Output:Double read GetOutput write SetOutput;
  6.  
  7. type
  8. INeuronReceptor = interface
  9.   function GetInput: specialize TDictionary<INeuronSignal, NeuralFactor>;
  10.   property Input: specialize TDictionary<INeuronSignal, NeuralFactor> read GetInput;
  11. end;
  12.  
  13. type
  14. INeuron = interface(INeuronSignal, INeuronReceptor) // <--- Error Interface cannot depend of 2 other Interfaces?
  15. end;    
  16.  

Any Idea, or it is not possible in Lazarus Pascal?

Thank you.
Dzandaa

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: using interface
« Reply #1 on: October 15, 2021, 12:25:03 pm »
AFAIK, no multiple Interface inheritance in FreePascal.
2 possible Methods come to mind:
1) "Chain" them
INeuronReceptor inherits from INeuronSignal
INeuron inherits from INeuronReceptor

2) Don't bother. A Class can inherit multiple interfaces.
Type MyClass = Class(TInterfacedObject, IInterface1, IInterface2 .... )
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Dzandaa

  • Full Member
  • ***
  • Posts: 248
  • From C# to Lazarus
Re: using interface
« Reply #2 on: October 15, 2021, 03:30:58 pm »
Thank you,

It seems to work, but now I'm stuck with that part:

Code: C  [Select][+][-]
  1.     public interface INeuralLayer : IList<INeuron>
  2.     {
  3.      // Etc...
  4.     }
  5.  

I read that there is an IInterfaceList, but I don't know how to use it...

I think I'll stop to convert my program, because the lack of documentation and examples.

Thank you anyway.


Dzandaa

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: using interface
« Reply #3 on: October 15, 2021, 03:40:31 pm »
There simply is no (standardized) interface for lists like there is in .Net, you'd have to roll your own or provide the necessary methods manually in your INeuralLayer.

 

TinyPortal © 2005-2018