Accessing Interfaces
From: SimonW (bozzzza_at_lycos.co.uk)
Date: 06/25/04
- Next message: Maarten Wiltink: "Re: Accessing Interfaces"
- Previous message: Maarten Wiltink: "Re: Simple threading question"
- Next in thread: Maarten Wiltink: "Re: Accessing Interfaces"
- Reply: Maarten Wiltink: "Re: Accessing Interfaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Jun 2004 09:15:51 +0100
I was wondering what is the best way to access methods when using
interfaces?
I have seen two types of examples; which are listed below.
One of them uses the Interface. The other access the implementation class
method directly.
I guess that example2 would not use reference counting so I would have to
free the object myself?
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;
- Next message: Maarten Wiltink: "Re: Accessing Interfaces"
- Previous message: Maarten Wiltink: "Re: Simple threading question"
- Next in thread: Maarten Wiltink: "Re: Accessing Interfaces"
- Reply: Maarten Wiltink: "Re: Accessing Interfaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|