Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Thread Tools Display Modes
Old 05-29-2010, 10:56 PM
johnacandy85 johnacandy85 is offline
Join Date: May 2010
Posts: 38
Unhappy Using an Interface (iinterface) in delphi ?? and Why ??

Today I thoght about reading on using interfaces in delphi. Though i used interfaces in .net and as far as i remember in .net interfaces were basically considered as abstract classes , i.e you couldnt create object of those classes and whenever there was a need of multiple inheritance people decided to use interface. However i am facing a bit of a proble implimenting interfaces in delphi.

Consider the code

MyInterface= Interface(IInterface) //Ctrl+shift+g
// Properties and their functions
function GetAge : Integer;
function GetMiles : Integer;

MyClass = class(TInterfacedObject, MyInterface)
function GetAge : Integer;
function GetMiles : Integer;

Now first of all why cant i go like this in the implimentation section
function Myinterface.GetAge : integer
showmessage ('function implimentation');

I found out that i have to declare the prototype of the function in the interface class in the derived class (MyClass) inorder to use them.
For example I have to redeclare
function GetAge : Integer;
in the MyClass

If this is true then whats the point of using an interface. I could have simply declared those functions in the Class itself and removing the Interface section should have no affect.
Then why use an interface if we cant define the interface function.
and why cant we go like
function Myinterface.GetAge : integer ;

I do remember in .net its different we could define interface functions and use them we just could use interface considering it as a base class only.

Any answers would be apprecited.. Thanks I am really confused...
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT. The time now is 03:46 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2015, vBulletin Solutions, Inc.