Solved

Trying to build a class with no property in it

Posted on 2001-07-12
16
131 Views
Last Modified: 2013-11-23
I built a class that I will be accessed from another class (kinda like a record). I wanna start the class from nothing, but Delphi forces it to be a TObject. That would be ok if only there was no properties added to those I make. Is there anyway to make them disapear?
Here's a sample of my code:
    Ttest = Class
      Private
        function pGetProp: Byte;
        procedure pSetProp(const Value: Byte);

      Published
        Property MyProperty: Byte Read pGetProp Write pSetProp;


0
Comment
Question by:comptebidon81
  • 5
  • 4
  • 2
  • +4
16 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6278459
? tobject didn't have propertys just methods

could you explain a bit more
0
 

Author Comment

by:comptebidon81
ID: 6278477
well, methods or properties, I don't wanna see them.
All I wanna see when I use my Class is the properties or Methods I defined.  (with the code completion)
I have to find a way either to hide those methods of the TObject, or to start my class out  of nothing.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278502
I don't think this is possible...
0
 

Author Comment

by:comptebidon81
ID: 6278553
What do you mean not possible?
TObject is a class. It was created out of nothing or at least has a Parent that was. If they managed to create it, why woudn't I be able to do the same?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278581
If you define a new class like this

TMyObject = class     // no ancestor specified
  ...
end;

it will automatically be derived from TObject. This is what the manual says.
0
 
LVL 2

Expert Comment

by:peymanz
ID: 6278588
It is not possible because, the delphi compiler is TObject aware. It forces all classes to be descendents of the TObject. However TObject does not have any properties. So all the properties you define are alone.

regards
// peymanz
0
 

Author Comment

by:comptebidon81
ID: 6278614
There might not be any properties, but there is a lot of functions and procedures like AfterConstruction and all those generally usefull things. Well, right now, their more anoying than usefull.

By the way, thanks for the explanation peymanz...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6278632
You can use a stinky record or a pointer list to build a class like thing without additional methods/properties. But then Delphi doesn't know that it is a class like thing, so code completion doesn't work on it nor all the other things that Delphi tries to help class builders with.

If you want all those Delphi goodies, you have no choice than using the keyword "class". And in that case Delphi silently forces you to use TObject as the class parent. That's it. I'm sorry, you have no choice.

Regards, Madshi.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:comptebidon81
ID: 6278871
So you say I have to choose between a record (wich will give me weeks and weeks of work) or to go on with the Class and try not to see those unwanted lines in the code completion?
 If only I could Hide them somehow. ...
0
 

Expert Comment

by:Bill_Door
ID: 6279230
if y're that concerned with your properties not being the only ones that come up, prefix them with and underscore (or whatever makes you comfortable) so they all come up in the same place.

An ugly solution I know....but y're trying to use the tool (Delphi) in a way it was not designed to be used.

Ed
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6279642
Maybe you can redeclare the methods/properties of TObject in your class, moving them to the private area. You'll get warnings as a result (but you can turn them off with a switch). In that case I guess that code completion will only show YOUR methods/properties, if code completion is used in a unit other than the one in that your object is defined. In the unit where your object is defined, you'll nevertheless see all methods.

I'm not sure if this idea would work at all, I've not tested it, it's just an idea...

Regards, Madshi.
0
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6279922
Hi comptebidon81,

if you'd like to build it from "nothing" then "class" is wrong ancestor, because it has predefined members. Would be better build it something like this:

  TMyObj = object
  private
    FProp: Integer;
    procedure SetProp(I: Integer);
  public
    property Prop: Integer read FProp write SetProp;
  end;

------
Igor.
0
 

Author Comment

by:comptebidon81
ID: 6280550
Thanks a lot, Igor! You saved me!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6280567
Hmmm... Sorry for giving false information to you. I didn't remember this "object". Never used it...
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6280651
Madshi,
do you never use Turbo Pascal?
Sorry, just a joke :-)
------
Igor
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6281170
I used it some years ago, but I can't remember having used the keyword "object". At the Turbo Pascal times I had not much reason to do object oriented programming. There records just were perfect...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now