Solved

IInterface, Interface?

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

22 Experts available now in Live!

Get 1:1 Help Now