Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 10th, 2012, 07:29 AM
Murugavel Murugavel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 28 Murugavel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 52 m 57 sec
Reputation Power: 0
Object creation in Implementation section...

Interface

Uses

Type
TSample = class (TObject)

end
Implementation

Uses

Type
TSample1 = Class (TSample)
end


I just need to access an object which is in implementation section of an object, is it possible ?
What's the use of this kind of object creation ?
Can we access this class(TSample1) from another class ?

Reply With Quote
  #2  
Old December 10th, 2012, 09:24 AM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 254 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 23 h 55 m 14 sec
Reputation Power: 5
I've never seen where you declare a TYPE in the implementation section of a unit. Sorry for the pun, but the implementation section implements the code using the types you declared in the interface section:

Code:
unit Unit1;

interface

uses
   ...;

type
  TSample = class (TObject)
  private
    privatevar: vartype;
    ...
    procedure privateProc1(myparam: paramtype);
    ..
  public
    publicvar: vartype;
    ...
    procedure publicProc1(myparam: paramtype);
  end;
  //you'd have to implement all of TSample's methods in Implementation section also.


  //assuming TSample is part of Form1

  TForm1 = class(TForm)
     //all your form's objects and methods
     procedure FormCreate(Sender: TObject);
     //You can create a TSample in FormCreate...
     procedure FormClose(Sender: TObject);
     //Destroy TSample in FormClose...
  private
     //Declare an instance of TSample Here
     MySample: TSample;
  public
    { Public declarations }
  end;

implementation
{$R *.DFM}

{TSample}//TSample Methods are implemented

procedure TSample.privateProc1(myparam: paramtype);
begin
    //implementation of TSample methods
end;

procedure TSample.publicProc1(myparam: paramtype);
begin
    //implementation of TSample methods
end;

{TForm1}//TForm Code implmentation

procedure TForm1.FormCreate(Sender: TObject);
begin
   MySample := TSample.Create(nil);
end;

procedure TForm1.FormClose(Sender: TObject);
begin
   MySample.Free;
   MySample := nil;
end;

end.

Reply With Quote
  #3  
Old December 11th, 2012, 01:04 AM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by Murugavel
Interface

Uses

Type
TSample = class (TObject)

end
Implementation

Uses

Type
TSample1 = Class (TSample)
end


I just need to access an object which is in implementation section of an object, is it possible ?


Yes, it is possible. In fact I have done it quite often.

Quote:
What's the use of this kind of object creation ?


To make the class "private" to the unit. So the class is not accessible from outside the unit.

Quote:
Can we access this class(TSample1) from another class ?


Only from code inside the same unit and after the "private" class declaration.

Final note: except for hiding the class from another unit I haven't found practical use of this approach. However from OOP point of view this is a good practice. Personally I done this only to avoid the "private" classes to show in Code Completion menu.

Reply With Quote
  #4  
Old December 14th, 2012, 06:56 AM
Murugavel Murugavel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 28 Murugavel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 52 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by Luthfi
Yes, it is possible. In fact I have done it quite often.



To make the class "private" to the unit. So the class is not accessible from outside the unit.



Only from code inside the same unit and after the "private" class declaration.

Final note: except for hiding the class from another unit I haven't found practical use of this approach. However from OOP point of view this is a good practice. Personally I done this only to avoid the "private" classes to show in Code Completion menu.



Thanks a lot,
I changed the access control, right now its available to other classes.

Reply With Quote
  #5  
Old December 14th, 2012, 12:17 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
Final note: except for hiding the class from another unit I haven't found practical use of this approach.

Another, dangerous but sometimes useful, reason is to gain access to the protected section of the ancestor class.

Reply With Quote
  #6  
Old December 14th, 2012, 12:28 PM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by clivew
Another, dangerous but sometimes useful, reason is to gain access to the protected section of the ancestor class.


You talked about "cracker" class. Unfortunately, if you read prior posts carefully you will see that we did not discuss about that.

Reply With Quote
  #7  
Old December 16th, 2012, 01:53 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
You talked about "cracker" class. Unfortunately, if you read prior posts carefully you will see that we did not discuss about that.

Hi Luthfi,
Sometimes I have difficulty understanding your responses.
When I simply reply to your comment that you have never found any other use for declaring an object type in the implementation section with another possibility why on earth would you respond by chastising me for not reading the prior posts?
It was you, after all, who introduced the idea that there were no other uses.

Having followed your posts and links for some time, I respect both your knowledge of Delphi and your willingness to share and help. I just get surprised by the acerbic nature of some of your responses to me.

Reply With Quote
  #8  
Old December 16th, 2012, 11:37 PM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by clivew
Hi Luthfi,
Sometimes I have difficulty understanding your responses.
When I simply reply to your comment that you have never found any other use for declaring an object type in the implementation section with another possibility why on earth would you respond by chastising me for not reading the prior posts?
It was you, after all, who introduced the idea that there were no other uses.

Having followed your posts and links for some time, I respect both your knowledge of Delphi and your willingness to share and help. I just get surprised by the acerbic nature of some of your responses to me.


I think you just never tried to understand my posts. You talked about cracker class which does not necessarily to be declared in implementation of a unit. So the purpose of that cracker class does not specifically tied with the advantage of declaring class in implementation of a unit.

Cracker class got its "benefits" from the fact that protected section is visible from descendant class(es).

When I said I found no other uses I talked about all kind of classes in general. Not cracker class, which (again) does not have to be declared in implementation.

Is that so hard to understand?

Last edited by Luthfi : December 16th, 2012 at 11:43 PM.

Reply With Quote
  #9  
Old December 17th, 2012, 01:02 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
Is that so hard to understand?

What is hard to understand is your acerbic attitude.

It is a fairly well known approach to hide a cracker class in the implementation section of the unit in which it is required rather than making it visible to the entire application.

In that respect I believe it was a legitimate observation in response to your comment about the limited uses of declaring an object type in the implementation section. Certainly not deserving of your derogatory suggestion that I should read the prior posts more carefully.

Anyway - enough of this. Either your attitude will mellow or it will not.
Let us turn to more productive conversations.

Reply With Quote
  #10  
Old December 18th, 2012, 04:39 AM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 15 sec
Reputation Power: 2
Quote:
Originally Posted by clivew
What is hard to understand is your acerbic attitude.


I don't see why do you feel so bitter about my attitude. Or was it your ego? Why don't you just answer the simple questions, and prove that cracker class must be declared in implementation section? If you can then I admit my mistake and apologize. If you can't, please don't pretend that the problem is my attitude.

Btw, I now seem to recall that you could never answer direct simple technical questions when the answers would disappointed you. I think you should work on that too.

Quote:
It is a fairly well known approach to hide a cracker class in the implementation section of the unit in which it is required rather than making it visible to the entire application.


Your response simply confirms my point. Declaring cracker class in implementation IS FOR HIDING. NOT A NECESSITY.

Quote:
In that respect I believe it was a legitimate observation in response to your comment about the limited uses of declaring an object type in the implementation section. Certainly not deserving of your derogatory suggestion that I should read the prior posts more carefully.


Then it's also a legitimate response that cracker class is not what we were talking here. BECAUSE IT DOES NOT NEED TO BE DECLARED IN IMPLEMENTATION SECTION.

Quote:
Anyway - enough of this. Either your attitude will mellow or it will not.
Let us turn to more productive conversations.


Like I have said before, I don't care about you.

Last edited by Luthfi : December 18th, 2012 at 04:42 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Object creation in Implementation section...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap