Introduction to OOP in Pascal
I don't see to many class examples in Pascal and Delphi. This is a pretty basic class just to show you the structure of it. I did not do an in depth error checking for all possible types of errors because it will kill time and my confuse some new users. This example introduces the following: Creating a class type, class constructor, class destructor, class private, public, property sections and their usage. I over killed on the commenting on the code but I wanted to make sure everybody could understand it. When I get time I show you other types of stuff you can do with classes in Delphi and free pascal compiler. Some of the things may be publish section which only allows its class to view data under it, or inherited classes. There is a virtual call and it works the same way as C++. It allows you to override a method from a derived classes, and of course I will show you how to inherit from the class. We will see where to go from there with object oriented programming in Delphi or Free Pascal Compiler. The only difference from Delphi class and Free Pascal Compiler is that you have to declare a directive in Free Pascal Compiler to tell the compiler you want to be able to create classes. Delphi already is setup so you don't have to worry about it. You will see my comment on the directive in the source code below. If you have any questions please feel free to ask, or if you have any advice you want to give me.
My next example will show you how to inheritance works with class. You can copy and paste the code in Delphi or Lazarus with no problem. Please vote if you learned anything or at least give me feedback. The more active you are the more active I will become and start posting on here. Enjoy!
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
Re-scan downloaded files using your personal virus checker before using it.
NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
If you don't have a virus scanner, you can get one at many places on the net
including:McAfee.com
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
Anybody had any trouble trying to port this to Delphi? I can convert these to Delphi XE (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)