IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphi PrismLanguage Details  Print This     

Cross Ref > Language Details

By Mike Prestwood

Delphi Prism versus PHP: A side by side comparison between Delphi Prism and PHP.

 
Language Details
 

Language Details is kind of a catch all for stuff that didn't make it into language basics nor any other category.

Custom Routines

[Other Languages] 

Languages Focus

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

Delphi Prism:   method, procedure, function

In Prism, everything is within a class (just like with C#, VB.Net, and Java). So you create class methods using the method keyword. Alternatively, you can use procedure or function if you want the compiler to enforce returning or not returning a value.

[function/procedure] RoutineName : ReturnType; 

As with C++, your custom routine must come before it's first usage or you have to prototype it in the Interface section.

Syntax Example:
method Form1.IntroduceYourself;
begin
  MessageBox.Show("Hello, I do not have a name yet.");
end;

procedure Form1.SayHello(pName: String);
begin
  MessageBox.Show("Hello " + pName);
end;
 
function Form1.Add(p1, p2 : Double): Double;
begin
  Result := p1 + p2;
end;
PHP:  "Custom Function" function

PHP uses functions and loosely typed parameters. Function definitions can come before or after their usage so my preference when mixing PHP in with a mostly HTML page is to put the functions after the </html> tag.

Syntax Example:
function sayHello($pName) {
 echo "Hello " . $pName . "<br>";
}
 
function add($p1, $p2) {
 return $p1 + $p2;
}




Event Handler

[Other Languages] 

In computer programming, an event handler is part of event driven programming where the events are created by the framework based on interpreting inputs. Each event allows you to add code to an application-level event generated by the underlying framework, typically GUI triggers such as a key press, mouse movement, action selection, and an expired timer. In addition, events can represent data changes, new data, etc. Specifically, an event handler is an asynchronous callback subroutine that handles inputs received in a program.

A custom event is a programmer created event. For example, you can contrast an event handler with a member event, an OOP concept where you add an event to a class.

Languages Focus

Many development environments and compilers provide for event driven programming, a standard set of application events such as startup, end, on click of a button, etc. This section documents the applicaton event handler or an overview for each language.

For OOP languages, do not confuse this section with class member events discussed in the OOP Details section of our Cross Reference Coding Encyclopedia.

Delphi Prism: 

The Prism event handler is based on the .Net event handler.

Most notable for Delphi developers is the fact that Prism does not offer initialization nor finalization sections.

More Info / Comment
[Not specified yet. Coming...]




Inline Code

[Other Languages] 

Languages Focus

Also known as embedded code where you embed another syntax language within the native code of the development environment you are using. The inline code can be compiled by the current development's compiler or by an external compiler.

Do not confuse with inlining which is a coding technique where custom routines are moved inline where the code is executed either by you, by a compiler directive, or automatically by the compiler.

Delphi Prism:   Not Supported

Prism does not support Delphi's asm keyword. Since all the .Net languages compile into intermediate language (IL), and not to a specific CPU, they do not provide support for inline assembler code.

[Not specified yet. Coming...]




Inlining

[Other Languages] 

General Info: Inline Routines

Instead of calling a routine, you move the code from the routine itself and expand it in place of the call. In addition to manual inlining, some languages support automatic inlining where the compiler or some other pre-compiler decides when to inline a code routine. Also, some languages allow for developer defined inlining where the developer can suggest and/or force the inlining of a code routine. Inlining can optimize your code for speed by saving a call and return, and parameter management.

Languages Focus

Does it support inlining? If so, does it support developer defined inlining? Does it support automatic inlining? Both?

Delphi Prism:   Automatic

In Prism, inlining is automatically done for you by the JIT compiler for all languages and in general leads to faster code for all programmers whether they are aware of inlining or not.

More Info / Comment  
[Not specified yet. Coming...]




Overloading

[Other Languages] 

Types of overloading include method overloading and operator overloading.

Method Overloading is where different functions with the same name are invoked based on the data types of the parameters passed or the number of parameters. Method overloading is a type of polymorphism and is also known as Parametric Polymorphism.

Operater Overloading allows an operator to behave differently based on the types of values used. For example, in some languages the + operator is used both to add numbers and to concatenate strings. Custom operator overloading is sometimes referred to as ad-hoc polymorphism.

Delphi Prism:   implicit

Like Delphi, Prism supports overloading. However, Prism supports implicit overloading (no need for an overload keyword).

Syntax Example:
method MainForm.Add(a, b: integer): Integer;
begin
Result := a + b;
end;
  
method MainForm.Add(const msg: String; a, b: integer): String;
begin
Result := msg + (a + b);
end;
PHP: 

PHP

  • Operator - No.
  • Method -
Syntax Example:

 





Parameters

[Other Languages] 
Delphi Prism:   var, const, out

Defining
Prism allows parameters of the same type to be listed together, separated by commas, and followed with a single data type (more params of different data types can follow, after a semi-colon).

By Reference or Value (and by constant and out)
The default for parameters is by value. For by reference, add var in front of the parameter. Prism also offers constant parameters where you add const in front of the parameter. A constant parameter is like a local constant or read-only parameter the compiler can optimize. You cannot assign a value to a constant parameter, nor can you pass one as a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can still modify the object's properties.) Finally, Prism offers an out parameter type which is like a var parameter except it does not have to be initialized prior.

Syntax Example:  
function Add(a, b: integer) : integer; 
begin
  Result := a + b;
end;
 
procedure ReplaceTime(var pDT: TDateTime; const pNewDT: TDateTime);
begin
end;
[Not specified yet. Coming...]




Self Keyword

[Other Languages] 
Delphi Prism:   Self

Within the implementation of a method, the identifier Self references the object in which the method is called. The Self variable is an implicit parameter for each object method. A method can use this variable to refer to its owning class.

To refer to the current instance of a class or structure, use the Self keyword. It provides a way to refer to the specific instance in which the code is currently executing. It is particularly useful for passing information about the currently executing instance.

You cannot use it with static method functions because static methods do not belong to an object instance. If you try, you'll get an error.

More Info / Comment
[Not specified yet. Coming...]




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


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