Solved

IInterface, Interface?

Posted on 2002-04-25
4
915 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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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