Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Friend in Delphi

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
GB
I am soon going to be teaching some OOP concepts at College, unfortunatly I must use Borland C++ (4.5), can anyone help with a translatikon of how this relates to Delphi, so I can get a better understanding of whats going on.

C++ has 'friend' declaration, looks a bit like a 'public' declaration in Delphi.
The info I have is
A Friend functionm is a non-member function which is allowed access to the private data
Public right?
the example I have looks like this
Code:
class Complex
{
// list of friend functions
friend float add_real(Complex&, Complex&);
private
  float, real, imag;
public
 Complex(float,float);
}
Is there some sort of pre declaration going on here (because C is low level rubbish) or what.
Please, no-one suggest the C++ forum, been there, dont want to go again.


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Can't get the Turbo versions of Delphi approved/installed?
 
Good idea Djangman, the problem is that they (The students) have already been using C++ (only the C aspects) since September.
I am taking over for the Planning and 'Basic OOP' bits of the course.
Trying to find out if the 'friend' thing is something you must do in C++ to make a function public. Because the students are at NQF level 3 (UK) they dont need a lot of high end stuff. So if they dont need 'friend' explaining I wont, you get the idea?
Love to show them the Delphi (object Pascal) model, but then they cannot try any code snippets.
I do have some C++ examples from when I did it at Uni.


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Friend classes are allowed access to other classes private/protected stuff. If they should be public, then define them as public.
 
Ok thanks TonHu, that plus a bit of googling, reveals that you can set up a simple class without 'friend' as I said this is for 'learners' (me included) I need to keep it simple.


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
I wish I knew more, I'm actually cross-working between Delphi and C# (in ASP.NET). First of all I know I could get Delphi.net now, but that's another story. I've been converting much of my previous delphi classes (OOP) into C# and I'm about as frustrated as you... For example a database table wrapper I built in D7 - in the end, it uses the exact same properties and such, just structured entirely different. I think you need to start teaching code conversion using OOP :p I wrote an article a while back here about OOP:

JD Solutions
 
Monday I will take them back over the stuff they need to be clear on, before they can start on OOP.
Structured programming(functions), Modularity, Structures(Records), etc.
I found some simple OOP tutorials on the web, should suffice for what I need.

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
I did Delphi and C/C++ in college. A friend allows instances of a friended class to see normally hidden methods and properties. To all classes that aren't friends of that class, they can't see those same methods and properties. C does have a public declaration if I remember correctly.

GIS Programmer
City of Orem, UT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top