IT SOLUTIONS
Your full service technology partner! 
+Expand
   ► KBTo/From GuidesDelphi Prism  Print This     

Constructor (Delphi Prism and VB Classic Cross Reference Guide)

By Mike Prestwood

Delphi Prism versus VB Classic: A side by side comparison between Delphi Prism and VB Classic.

 
OOP Details
 

More object oriented (OO) stuff.

Constructor

[Other Languages] 

General Info: Class Constructor

Constructors are called when you instantiate an object from a class. This is where you can initialize variables and put code you wish executed each time the class is created. When you initially set the member fields and properties of an object, you are initializing the state of the object. The state of an object is the values of all it's member fields and properties at a given time.

Languages Focus

What is the syntax? Can you overload constructors? Is a special method name reserved for constructors?

Delphi Prism:  "Constructors" constructor + class name

In Prism, a constructor is called whenever a class or struct is created. You use the constructor keyword with an unnamed method. You can overload the constructor simply by adding two or more unnamed methods with various parameters.

Prism also supports a Create constructor method for backward compatibility with Delphi for Win32.

If you do not create a constructor, Prism will create an implicit constructor that initializes all member fields to their default values.

Constructors can execute at two different times. Static constructors are executed by the CLR before any objects are instantiated. Regular constructors are executed when you create an object.

Syntax Example:
Cyborg = public class
public
  constructor();
  constructor(pName: String);
end;
VB Classic:  "Constructors" Class_Initialize

When an object instance is created from a class, VB6 calls a special parameter-less sub named Class_Initialize. Since you cannot specify parameters for this sub, you also cannot overload it.

When a class is destroyed, VB6 calls a special sub called Class_Terminate.

More Info / Comment  












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]