Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IInterface, Interface?

Posted on 2002-04-25
4
Medium Priority
?
917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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