[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

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
0
GOMF
Asked:
GOMF
  • 4
  • 2
  • 2
  • +3
1 Solution
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now