Difference between revisions of "Interfaces"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "Interfaces can be utilized as an alternative solution to the need of multiple inheritance, which Object Pascal currently does not support. ==Full example program== <delphi> ...")
 
m (wiki syntax straightened)
Line 3: Line 3:
 
==Full example program==
 
==Full example program==
  
<delphi>
+
<source lang="pascal">
 
program project1;
 
program project1;
  
Line 41: Line 41:
 
   TestDelegate;
 
   TestDelegate;
 
end.
 
end.
</delphi>
+
</source>
  
 
[[Category:Pascal]]
 
[[Category:Pascal]]

Revision as of 21:00, 1 January 2013

Interfaces can be utilized as an alternative solution to the need of multiple inheritance, which Object Pascal currently does not support.

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.