Difference between revisions of "Interfaces"

From Free Pascal wiki
(Distinguish from "interface".)
(Expand slightly.)
 
Line 1: Line 1:
Interfaces can be utilized as an alternative solution to the need of multiple inheritance, which Object Pascal currently does not support. These are distinct from the '''interface''' reserved word.
+
Interfaces can be utilized as an alternative solution to the need of multiple inheritance, which Object Pascal currently does not support. These are distinct from the [[Interface]] reserved word which relates to program structure.
  
 
==Full example program==
 
==Full example program==

Latest revision as of 12:45, 25 February 2020

Interfaces can be utilized as an alternative solution to the need of multiple inheritance, which Object Pascal currently does not support. These are distinct from the Interface reserved word which relates to program structure.

Full example program

program project1;

{$mode delphi}
{$interfaces corba}

type
  IMyDelegate = interface
    procedure DoThis (value: integer);
  end;

  TMyClass = class (TInterfacedObject, IMyDelegate)
    procedure DoThis (value: integer);
  end;

procedure TestDelegate;
var
  delegate: TMyClass;
  intfdelegate: IMyDelegate;
begin
  delegate := TMyClass.Create;
  intfdelegate := IMyDelegate(delegate);
  intfdelegate.DoThis(1);
end;

{ TMyClass }

procedure TMyClass.DoThis(value: integer);
var
  Str: string;
begin
  WriteLn('Success!!! Type <enter> to continue');
  ReadLn(Str);
end;

begin
  TestDelegate;
end.

See also