Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

qoy (i do not have that many points :-)

Posted on 2002-06-16
10
Medium Priority
?
148 Views
Last Modified: 2010-04-04
Could a private constructor be useful for a Delphi object? Describe a constallation.
What is the problem of Delphi 5 (maybe also 4 and 6) with a private constructor?

100 points for an answer to both parts. 50 for one part.
No sample code required. A good explanation is enough.
Maybe more points for a good description.
0
Comment
Question by:robert_marquardt
[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
  • 3
  • 3
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7083126
qoy->question of the year?

never used a private constructor,
no idea whats thebenefit of of ths

listening . . .

meikl ;-)
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 7083177
To precise the question: ONLY a private constructor!
Yes, it IS useful.
0
 
LVL 17

Accepted Solution

by:
geobul earned 800 total points
ID: 7083193
Hi,
Nice question, Robert.

I've never used it before but made some tests. And the tests show that:
1. if the object is created in the same unit then the private constructor is executed.
2. if the object is created outside its unit then the inherited constructor is used instead.

So, the conclusion:
A private constructor could be useful for an object which is used by another object in the same unit to perform some special operations (initialization) which are specific to that second (master) object and are not mandatory when the first object is used by itself.

Is that clear enough (understandable)? Does that make sense?

Regards, Geo
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:geobul
ID: 7083217
About your second question: I can't find out any problems using private constructors in Delphi 5. What did you have in mind?
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 7083268
geobul, almost there.
1. not bad, but i have a more useful task implemented already
2. you mentioned the problem, but failed to recognize it.
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 7088984
I will solve the question tomorrow.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7089016
yep, do it :-)
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 7091834
I use a private constructor as geobul mentioned. A controller object (component) creates them. The objects itself represent USB devices. No user interference is needed because the devices are plugged and as reaction a device object is created. A user/program created object is not advisable here because a 1 : 1 representation is always needed. For that i wanted to make it impossible to create a device object.

The problem is mentioned by geobul as 2. The TObject.Create is not hidden because it is a static method not a virtual method.
This i consider as a language problem. Visibility clashes with inheritance.
Locally the private constructor hides the TObject.Create. Externally TObject.Create is still visible.
I also get no visibility warning like for virtual methods. So the most difficult to understand language part is completely unvocered by hints or warnings.

I will award geobul the 100 points. Maybe more. It was a really tricky question.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7092386
aplause ;-)
0
 
LVL 17

Expert Comment

by:geobul
ID: 7092527
Wow, so many many thanks, Robert :-)))

I see what you had in mind now. On the one hand that is some kind of flexibility but on the other hand the lack of warning messages is really bad. This may lead to very-hard-to-find errors.

Thank you again and best regards, Geo
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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