Inheritance in Delphi

Hey guys,

I am building a tottally new protect and I want strict inheritance and OOP use...I've got a problem... ;-)

If I have a type record...and I want that type record to be inherited to other classes..its data that most classes need..BUT I want to be able to avoid using "Uses Globalnames.." in my mainprogram...How do I create a RECORD (type) in my class..is that possible..am I beeing stupid for wanting this ...?? ..be gentle..
'

Regards,

GOMF
GOMFAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Mmmh, first of all, you cannot inherit a record type. This type is defined and period. Now I come to the point I don't understand. You have defined the record and you want to use it in various classes,right? If the record has a variable to instantiate it the it is also valid in all descendants of the base class (though, usually not accessible). What do you need now? Access to the record from derived classes or making it public?

Ciao, Mike
0
simonetCommented:
Why not use a TPersistent instead?

Alex
0
King_DavidCommented:
2 options:

1. Use a class instead of a record.
2. Put the record in a class and inherit
   the class.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

GOMFAuthor Commented:
King_David :

Can you please elaborate that a bit..I can't define a record in a class..and I am not happy about having 30 diff. variables defined in a class..


Regards,

GOMF
0
King_DavidCommented:
Example:
type
  TMyRec = record
    Field1: integer;
    Field2: byte;
  end;

  TMyClass = class
  public
    MyRec: TMyRec;
    ...
  end;

  TMyNewClass = class(TMyClass)
    ...
  end;

By the way, why not put many fields in
a class?
A class is just a powerful record.
When you inherit a class, the class
acts like a record, you don't even have
to create it.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LischkeCommented:
GOMF, you requested that we should be gently but what about you? Would you please also reply to the other tips you got! If you would a bit more specific then your problem could probably already solved. What do you mean with "define a record in a class"? Is it something like:

type
  TMyClass = class
  private
    FT: record
      A, B: Integer;
    end;
  end;

This works very well. Where IS now your problem?

Ciao, Mike
0
ptmcompCommented:
You can use the same record in diffrent ways using 'case of'. The disadvantage is that you have to define the whole record at one place. What's about pointers to records? Diffrent record definitions could refer the same memory (be carefull about the size of the records, because it's kind of hard typecasting).
ptm.
0
GOMFAuthor Commented:
Exacto mundo - thanks David.

Lischke,

Take it easy Lischke, no reason to get excited, I was just not good enough to explain what it was I wanted, but David got it ;-)


Thanks for your help guys.


Regards,

GOMF
0
LischkeCommented:
Hu? I don't see any significant differences between David's and my comment. Finally, it is your decision GOMF. You can accept whatever comment you like. But don't make it too often like in this question or you may left alone if you have really difficult questions...

Ciao, Mike
0
ronit051397Commented:
Lischke,

With all the respect to your knowledge, you should calm down. If you are fed up with beginners or questions like this one, then don't enter these threads in the first place.

Ronit,
0
LischkeCommented:
Hi Ronit,

point taken. I'll stop my complaints. As you perhaps know, I've always been a very kind and polite person and intend to stay so. Hence there must be a good reason when I change this behavior temporarily.

Anyway, thank you for respectfully telling me that I was wrong ;-)

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.