🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.objectpascal
1 messages
1 total messages Started by SimonW Thu, 24 Jun 2004 14:51
Which instance when using Iinterface
#16
Author: SimonW
Date: Thu, 24 Jun 2004 14:51
48 lines
1969 bytes
I was wondering when you want to access a method in an 'interface
implementation class' what is the best way?

I have seen both types of examples; which are listed below. I take it for
example2 I would need to free the object after I have finished with it: I am
guessing example2 would not use reference counting ?

TIA

Simon.


Type

  IInterfaceExample = interface(IInterface)
    ['{24868058-9C85-48C4-97E7-D0D730F61962}']
    function add(a,b : Integer) : Integer; stdcall;
  end;

   TInterFaceExample = class(TInterfacedObject,IInterfaceExample)
    function add(a,b : Integer) : Integer; stdcall;
  end;

 implementation

  function TInterfaceExample.add(a, b: Integer): Integer;
  begin
    result := a+b;
  end;

 var
   classInterfaceExample : TInterfaceExample;
   interInterfaceExample : IInterfaceExample;

  begin

   //Example 1 for accessing function
     interInterfaceExample := TInterfaceExample.create;
     answer := interInterfaceExample1.add(1,2);
     showMessage(format('%d',[answer]));

   //Example 2 for accessing function
     classInterfaceExample := TinterfaceExample.Create;
     answer := classInterfaceExample.add(1,2);
     showMessage(format('%d',[answer]));
     classInterfaceExample.Free;

 end;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads