Solved

IInterface, Interface?

Posted on 2002-04-25
4
910 Views
Last Modified: 2008-02-01
Hi experts,

I have some difficulties trying to understand the concept of Delphi IInterface/Interface. Could someone give some brief introduction or tutorial links about this topic?

Simple examples would be most appreciated.

Thank you in advance.
0
Comment
Question by:ourselves
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6970435
hi,
you should find some good reading here:

http://delphi.about.com/cs/comoleactivex/
0
 
LVL 3

Accepted Solution

by:
rondi earned 50 total points
ID: 6970601
An interface is basically a description of procedures, functions and properties supported by an object.

You can create an interface that will provide date and
time information for example:

IDateTime = interface
  function GetDate: TDateTime;
  function DayOfWeek(date: TDateTime): Byte;
end;


So the interface doesn't actually do anything; now classes
& objects can be created that support this interface.
Example:

TDateTimeProvider = class(TInterfacedObject, IDateTime)
protected
  function GetDate: TDateTime;
  function DayOfWeek(date: TDateTime): Byte;
end;
//.... further down

function TDateTimeProvider.GetDate: TDateTime;
begin
  Result := Now;
end;

Basically 2 people could create 2 different objects that
both support the IDateTime interface. A third developer
could then use either of the 2 objects, all he needs to
know is that the interface supports the GetDate and DayOfWeek methods.

Once people know about the IDateTime interface, anyone can
go ahead and create a class that supports it, and provides
the actuall functionality.

So an interface is basically a contract: any objects that
are based on the interface, must support the interface's
methods exactly as they are defined in the interface.

IInterface is the base interface type. It's like TObject
for Delphi classes. On Windows it's the same as IUnknown,
but on Linux it's different. It basically enables Delphi
guys to write interfaces that'll work fine on Windows & Linux.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6970763
Perfect explanation, rondi.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6971400
my comment exactly :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question