Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-29-2010, 09:56 PM
johnacandy85 johnacandy85 is offline
Member
 
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
['{515E5E54-5DEE-4C15-881B-5F5FAD4AFAC5}']
// Properties and their functions
function GetAge : Integer;
function GetMiles : Integer;
end;

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

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

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 ;
begin
.........
end;

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
Reply

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 10:59 AM.


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