Difference between revisions of "Delphi language features missing from the Free Pascal Compiler"

From Lazarus wiki
Jump to navigationJump to search
Line 9: Line 9:
 
==== Records with Methods ====
 
==== Records with Methods ====
 
==== Class Variables, Types and Consts ====
 
==== Class Variables, Types and Consts ====
 +
 +
<delphi>
 +
program ClassTest;
 +
 +
{$APPTYPE CONSOLE}
 +
 +
type
 +
  TSomeClass = class
 +
  private
 +
    type
 +
      TSomeType = type integer;    // an internal type
 +
    class var
 +
      FSomeClassVar: TSomeType;    // class variable belongs to class, not an instance
 +
    var
 +
      FSomeIntanceVar: TSomeType;  // instance variable belongs to instance. it is a usual field
 +
    class procedure SetSomeClassVar(const AValue: TSomeType); static;
 +
  public
 +
    class property SomeProperty: TSomeType read FSomeClassVar write SetSomeClassVar; // class property - belongs to class
 +
    property SomeInstanceProp: TSomeType read FSomeIntanceVar;
 +
  end;
 +
 +
{ TSomeClass }
 +
 +
class procedure TSomeClass.SetSomeClassVar(const AValue: TSomeType);
 +
begin
 +
  FSomeClassVar := AValue;
 +
end;
 +
 +
var
 +
  SomeClass: TSomeClass;
 +
begin
 +
  SomeClass.SomeProperty := 1;
 +
  WriteLn(SomeClass.SomeProperty);
 +
end.
 +
</delphi>
 +
 
==== Class Properties ====
 
==== Class Properties ====
 
==== Static Class Methods ====
 
==== Static Class Methods ====

Revision as of 09:19, 8 November 2009

New since Delphi 2007

Operator Overloading Syntax for records and classes

Info: http://docwiki.embarcadero.com/RADStudio/en/Operator_Overloading http://wiert.wordpress.com/2009/10/19/delphi-operator-overloading-table-of-operators-names-and-some-notes-on-usage-and-glitches/

Class Helpers

Records with Methods

Class Variables, Types and Consts

<delphi> program ClassTest;

{$APPTYPE CONSOLE}

type

 TSomeClass = class
 private
   type
     TSomeType = type integer;    // an internal type
   class var
     FSomeClassVar: TSomeType;    // class variable belongs to class, not an instance
   var
     FSomeIntanceVar: TSomeType;  // instance variable belongs to instance. it is a usual field
   class procedure SetSomeClassVar(const AValue: TSomeType); static;
 public
   class property SomeProperty: TSomeType read FSomeClassVar write SetSomeClassVar; // class property - belongs to class
   property SomeInstanceProp: TSomeType read FSomeIntanceVar;
 end;

{ TSomeClass }

class procedure TSomeClass.SetSomeClassVar(const AValue: TSomeType); begin

  FSomeClassVar := AValue;

end;

var

 SomeClass: TSomeClass;

begin

 SomeClass.SomeProperty := 1;
 WriteLn(SomeClass.SomeProperty);

end. </delphi>

Class Properties

Static Class Methods

New since Delphi 2009

Generics Syntax

Unicode string support

Anonymouse Methods

New since Delphi 2010

Custom Attributes

Enhanced RTTI

Delayed directive

Info is here: http://docwiki.embarcadero.com/RADStudio/en/Libraries_and_Packages#Delayed_Loading

fpc wiki about that topic: http://wiki.freepascal.org/Dynamically_loading_headers

AS and IS extended for interfaces

Info is here: http://docwiki.embarcadero.com/RADStudio/en/Interface_References#Casting_Interface_References_to_Objects

Misc:

  1. {$SCOPEDENUMS ON} directive which allows to use enumeration name before the item. Example:

<delphi> type

 TColor = (red, green, blue);

begin

 WriteLn(ord(TColor.red));

end; </delphi>

  1. {$pointermath ON} directive which turns on pointer arithmetic.

Reference

  1. http://edn.embarcadero.com/article/34324
  2. http://edn.embarcadero.com/article/images/39076/New_Delphi_Coding_Styles_and_Architectures.pdf
  3. http://docwiki.embarcadero.com/RADStudio/en/What's_New_in_Delphi_and_C%2B%2BBuilder_2010