Recent

Author Topic: [SOLVED] Interface and overload method  (Read 1250 times)

superc

  • Full Member
  • ***
  • Posts: 241
[SOLVED] Interface and overload method
« on: May 21, 2021, 09:03:06 am »
Hello,

I want use interface in my project for a group of similar frame:

Code: Pascal  [Select][+][-]
  1. type
  2.   IFrameInterface = interface
  3.     ['{E1AFD96E-741B-4209-9DC5-6EF45BFD2A5B}']
  4.     procedure assignComponentValue;
  5.     procedure initFrame(pointedObject: TObject);
  6.     procedure ClearVariables;
  7.   end;  
  8.  

It's possible overload a method in Interface, or do I have to declare another one?

Thanks in advance
« Last Edit: May 21, 2021, 10:02:05 am by superc »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Interface and overload method
« Reply #1 on: May 21, 2021, 09:16:06 am »
Not in the interface, but It's perfectly posible, both in the interface definition and in the class implementing it:
Code: Pascal  [Select][+][-]
  1.   IFrameInterface = interface
  2.     ['{E1AFD96E-741B-4209-9DC5-6EF45BFD2A5B}']
  3.     procedure assignComponentValue;
  4.     procedure initFrame(pointedObject: TObject);
  5.     { Overload in the interface:
  6.      procedure initFrame(BaseControl: TControl);}
  7.     procedure ClearVariables;
  8.   end;
  9.  
  10.   TFrame1 = class(TFrame, IFrameInterface)
  11.     { Interface implementation }
  12.     procedure assignComponentValue;
  13.     procedure initFrame(pointedObject: TObject);
  14.     procedure ClearVariables;
  15.     { Overload for this specific class, if not on the interface }
  16.     procedure initFrame(BaseControl: TControl);
  17.   end;

The method(s) whose signature match the interface will be its implementation; any other overload (in the class) will be just a normal method.
« Last Edit: May 21, 2021, 09:19:38 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

superc

  • Full Member
  • ***
  • Posts: 241
Re: Interface and overload method
« Reply #2 on: May 21, 2021, 09:21:36 am »
Not in the interface, but It's perfectly posible, both in the interface definition and in the class implementing it:
Code: Pascal  [Select][+][-]
  1.   IFrameInterface = interface
  2.     ['{E1AFD96E-741B-4209-9DC5-6EF45BFD2A5B}']
  3.     procedure assignComponentValue;
  4.     procedure initFrame(pointedObject: TObject);
  5.     { Overload in the interface:
  6.      procedure initFrame(BaseControl: TControl);}
  7.     procedure ClearVariables;
  8.   end;
  9.  
  10.   TFrame1 = class(TFrame, IFrameInterface)
  11.     { Interface implementation }
  12.     procedure assignComponentValue;
  13.     procedure initFrame(pointedObject: TObject);
  14.     procedure ClearVariables;
  15.     { Overload for this specific class, if not on the interface }
  16.     procedure initFrame(BaseControl: TControl);
  17.   end;

The method(s) whose signature match the interface will be its implementation; any other overload (in the class) will be just a normal method.

Wonderful solution!!
Thanks


 

TinyPortal © 2005-2018