Solved

IInterface, Interface?

Posted on 2002-04-25
4
902 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now