🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #16

Which instance when using Iinterface

#16
From: 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;
Technical Details
Message-ID: <2k0849F16cag5U1@uni-berlin.de>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d30,2fc81e4f57de30e8,start
X-Google-Attributes: gid109d30,public
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: "SimonW" <bozzzza@lycos.co.uk>
Newsgroups: borland.public.delphi.language.objectpascal
Subject: Which instance when using Iinterface
Date: Thu, 24 Jun 2004 15:51:52 +0100
Lines: 50
Message-ID: <2k0849F16cag5U1@uni-berlin.de>
X-Trace: news.uni-berlin.de h3vSGA4BomiqJpjuaiXRbQy2vQEcw256SoZnci9H+HqxjrnBpL
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409