Share to: share facebook share twitter share wa share telegram print page

Oxygene (programming language)

Oxygene
DeveloperRemObjects Software
First appeared2005; 19 years ago (2005)[1]
PlatformCommon Language Infrastructure, Java, Cocoa, CPU-Native, Windows 32/64 bit, Linux 32/64 bit, WebAssembly
LicenseTrialware
Websiteelementscompiler.com/elements/oxygene/
Influenced by
Delphi's Object Pascal, C#

Oxygene (formerly known as Chrome) is a programming language developed by RemObjects Software for Microsoft's Common Language Infrastructure, the Java Platform and Cocoa. Oxygene is based on Delphi's Object Pascal, but also has influences from C#, Eiffel, Java, F# and other languages.

Compared to the now deprecated Delphi.NET, Oxygene does not emphasize total backward compatibility, but is designed to be a "reinvention" of the language, be a good citizen on the managed development platforms, and leverage all the features and technologies provided by the .NET and Java runtimes.

Oxygene is a commercial product and offers full integration into Microsoft's Visual Studio IDE on Windows, as well as its own IDE called Fire for use on macOS. Oxygene is one of six languages supported by the underlying Elements Compiler toolchain, next to C#, Swift, Java, Go and Mercury (based on Visual Basic.NET).

From 2008 to 2012, RemObjects Software licensed its compiler and IDE technology to Embarcadero to be used in their Embarcadero Prism product.[2] Starting in the Fall of 2011, Oxygene became available in two separate editions, with the second edition adding support for the Java and Android runtimes. Starting with the release of XE4, Embarcadero Prism is no longer part of the RAD Studio SKU. Numerous support and upgrade paths for Prism customers exist to migrate to Oxygene.[3] As of 2016, there is only one edition of Oxygene, which allows development on Windows or macOS, and which can create executables for Windows, Linux, WebAssembly .NET, iOS, Android, Java and macOS.

The language

The Oxygene language has its origins in Object Pascal in general and Delphi in particular, but was designed to reflect the guidelines of .NET programming and to create fully CLR-compliant assemblies. Therefore, some minor language features known from Object Pascal / Delphi have been dropped or revised, while a slew of new and more modern features, such as Generics or Sequences and Queries have been added to the language.

Oxygene is an object-oriented language, which means it uses classes, which can hold data and execute code, to design programs.[clarification needed] Classes are "prototypes" for objects, like the idea of an apple is the prototype for the apple one can actually buy in a shop. It is known that an apple has a colour, and that it can be peeled: those are the data and executable "code" for the apple class.

Oxygene provides language-level support for some features of parallel programming. The goal is to use all cores or processors of a computer to improve performance. To reach this goal, tasks have to be distributed among several threads. The .NET Framework's ThreadPool class offered a way to efficiently work with several threads. The Task Parallel Library (TPL) was introduced in .NET 4.0 to provide more features for parallel programming.

Operators can be overloaded in Oxygene using the class operator syntax:

class operator implicit(i : Integer) : MyClass;

Note, that for operator overloading each operator has a name, that has to be used in the operator overloading syntax, because for example "+" would not be a valid method name in Oxygene.[4]

Program structure

Oxygene does not use "Units" like Delphi does, but uses .NET namespaces to organize and group types. A namespace can span multiple files (and assemblies), but one file can only contain types of one namespace. This namespace is defined at the very top of the file:

namespace ConsoleApplication1;

Oxygene files are separated into an interface and an implementation section, which is the structure known from Delphi. The interface section follows the declaration of the namespace. It contains the uses clause, which in Oxygene imports types from other namespaces:

uses
  System.Linq;

Imported namespaces have to be in the project itself or in referenced assemblies. Unlike in C#, in Oxygene alias names cannot be defined for namespaces, only for single type names (see below).

Following the uses clause a file contains type declarations, like they are known from Delphi:

interface

type
  ConsoleApp = class
  public
    class method Main;
  end;

As in C#, the Main method is the entry point for every program. It can have a parameter args : Array of String for passing command line arguments to the program.

More types can be declared without repeating the type keyword.

The implementation of the declared methods is placed in the implementation section:

implementation

class method ConsoleApp.Main;
begin
  // add your own code here
  Console.WriteLine('Hello World.');
end;

end.

Files are always ended with end.

Types

As a .NET language, Oxygene uses the .NET type system: There are value types (like structs) and reference types (like arrays or classes).

Although it does not introduce own "pre-defined" types, Oxygene offers more "pascalish" generic names for some of them,[5] so that for example the System.Int32 can be used as Integer and Boolean (System.Boolean), Char (System.Char), Real (System.Double) join the family of pascal-typenames, too. The struct character of these types, which is part of .NET, is fully preserved.

As in all .NET languages types in Oxygene have a visibility. In Oxygene the default visibility is assembly, which is equivalent to the internal visibility in C#. The other possible type visibility is public.

type
  MyClass = public class
end;

The visibility can be set for every type defined (classes, interfaces, records, ...).

An alias name can be defined for types, which can be used locally or in other Oxygene assemblies.

type
  IntList = public List<Integer>; //visible in other Oxygene-assemblies
  SecretEnumerable = IEnumerable<String>; //not visible in other assemblies

Public type aliases won't be visible for other languages.

Records

Records are what .NET structs are called in Oxygene. They are declared just like classes, but with the record keyword:

type
  MyRecord = record
    method Foo;
  end;

As they're just .NET structs, records can have fields, methods and properties, but do not have inheritance and cannot implement interfaces.

Interfaces

Interfaces are a very important concept in the .NET world, the framework itself makes heavy use of them. Interfaces are the specification of a small set of methods, properties and events a class has to implement when implementing the interface. For example, the interface IEnumerable<T> specifies the GetEnumerator method which is used to iterate over sequences.

Interfaces are declared just like classes:

type
  MyInterface = public interface
    method MakeItSo : IEnumerable;
    property Bar : String read write;
  end;

Please notice, that for properties the getter and setter are not explicitly specified.

Delegates

Delegates define signatures for methods, so that these methods can be passed in parameters (e.g. callbacks) or stored in variables, etc. They're the type-safe NET equivalent to function pointers. They're also used in events. When assigning a method to a delegate, one has to use the @ operator, so the compiler knows, that one doesn't want to call the method but just assign it.

Oxygene can create anonymous delegates; for example methods can be passed to the Invoke method of a control without declaring the delegate:

method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs);
begin
  Invoke(@DoSomething);
end;

An anonymous delegate with the signature of the method DoSomething will be created by the compiler.

Oxygene supports polymorphic delegates, which means, that delegates which have parameters of descending types are assignment compatible. Assume two classes MyClass and MyClassEx = class(MyClass), then in the following code BlubbEx is assignment compatible to Blubb.

type
  delegate Blubb(sender : Object; m : MyClass);
  delegate BlubbEx(sender : Object; mx : MyClassEx);

Fields can be used to delegate the implementation of an interface, if the type they're of implements this interface:

Implementor = public class(IMyInterface)
  // ... implement interface ...
end;

MyClass = public class(IMyInterface)
  fSomeImplementor : Implementor; public implements IMyInterface; //takes care of implementing the interface
end;

In this example the compiler will create public methods and properties in MyClass, which call the methods / properties of fSomeImplementor, to implement the members of IMyInterface. This can be used to provide mixin-like functionality.[6]

Anonymous methods

Anonymous methods are implemented inside other methods. They are not accessible outside of the method unless stored inside a delegate field. Anonymous methods can use the local variables of the method they're implemented in and the fields of the class they belong to.

Anonymous methods are especially useful when working with code that is supposed to be executed in a GUI thread, which is done in .NET by passing a method do the Invoke method (Control.Invoke in WinForms, Dispatcher.Invoke in WPF):

method Window1.PredictNearFuture;  //declared as async in the interface
begin
  // ... Calculate result here, store in variable "theFuture"
    Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, method; begin
      theFutureTextBox.Text := theFuture;
    end);
end;

Anonymous methods can have parameters, too:

method Window1.PredictNearFuture;  //declared as async in the interface
begin
  // ... Calculate result here, store in variable "theFuture"
    Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, method(aFuture : String); begin
      theFutureTextBox.Text := aFuture ;
    end, theFuture);
end;

Both source codes use anonymous delegates.

Property notification

Property notification is used mainly for data binding, when the GUI has to know when the value of a property changes. The .NET framework provides the interfaces INotifyPropertyChanged and INotifyPropertyChanging (in .NET 3.5) for this purpose. These interfaces define events which have to be fired when a property is changed / was changed.

Oxygene provides the notify modifier, which can be used on properties. If this modifier is used, the compiler will add the interfaces to the class, implement them and create code to raise the events when the property changes / was changed.

property Foo : String read fFoo write SetFoo; notify;
property Bar : String; notify 'Blubb'; //will notify that property "Blubb" was changed instead of "Bar"

The modifier can be used on properties which have a setter method. The code to raise the events will then be added to this method during compile time.

Code examples

Hello World

namespace HelloWorld;

interface

type
  HelloClass = class
  public
    class method Main;
  end;

implementation

class method HelloClass.Main;
begin
  writeLn('Hello World!');
end;

end.

Generic container

namespace GenericContainer;

interface

type
  TestApp = class
  public
    class method Main;
  end;

  Person = class
  public
    property FirstName: String;
    property LastName: String;     
  end;

implementation

uses
  System.Collections.Generic;

class method TestApp.Main;
begin
  var myList := new List<Person>; //type inference
  myList.Add(new Person(FirstName := 'John', LastName := 'Doe')); 
  myList.Add(new Person(FirstName := 'Jane', LastName := 'Doe'));
  myList.Add(new Person(FirstName := 'James', LastName := 'Doe')); 
  Console.WriteLine(myList[1].FirstName);  //No casting needed
  Console.ReadLine;       
end;

end.

Generic method

namespace GenericMethodTest;

interface

type
GenericMethodTest = static class
public
  class method Main;
private
  class method Swap<T>(var left, right : T);
  class method DoSwap<T>(left, right : T);
end;

implementation

class method GenericMethodTest.DoSwap<T>(left, right : T);
begin
  var a := left;
  var b := right;
  Console.WriteLine('Type: {0}', typeof(T));
  Console.WriteLine('-> a = {0}, b = {1}', a , b);
  Swap<T>(var a, var b);
  Console.WriteLine('-> a = {0}, b = {1}', a , b);
end;

class method GenericMethodTest.Main;
begin
  var a := 23;// type inference
  var b := 15;
  DoSwap<Integer>(a, b); // no downcasting to Object in this method.

  var aa := 'abc';// type inference
  var bb := 'def';
  DoSwap<String>(aa, bb); // no downcasting to Object in this method.

  DoSwap(1.1, 1.2); // type inference for generic parameters
  Console.ReadLine();
end;

class method GenericMethodTest.Swap<T>(var left, right : T);
begin
  var temp := left;
  left:= right;
  right := temp;
end;

end.

Program output:

Type: System.Int32
-> a = 23, b = 15
-> a = 15, b = 23
Type: System.String
-> a = abc, b = def
-> a = def, b = abc
Type: System.Double
-> a = 1,1, b = 1,2
-> a = 1,2, b = 1,1

Differences between Delphi and Oxygene

  • unit: Replaced with the namespace keyword. Since Oxygene doesn't compile per-file but per-project, it does not depend on the name of the file. Instead the unit or namespace keyword is used to denote the default namespace that all types are defined in for that file
  • procedure and function: method is the preferred keyword, though procedure and function still work.
  • overload: In Oxygene all methods are overloaded by default, so no special keyword is needed for this
  • .Create(): This constructor call has been replaced by the new keyword. It can still be enabled in the project options for legacy reasons
  • string: Characters in strings are zero-based and read-only. Strings can have nil values, so testing against empty string is not always sufficient.

Criticism

Some people[who?] would like to port their Win32 Delphi code to Oxygene without making major changes. This is not possible because while Oxygene looks like Delphi, there are enough changes so as to make it incompatible for a simple recompile. While the name gives it the appearance of another version of Delphi, that is not completely true.[7]

On top of the language difference, the Visual Component Library framework is not available in Oxygene.[8] This makes porting even more difficult because classic Delphi code relies heavily on the VCL.

See also

References

  1. ^ "Evolution of the Oxygene Language | Oxygene | Elements". Archived from the original on 2018-01-05. Retrieved 2018-01-04.
  2. ^ "Embarcadero Prism page, at the bottom of the page an image stating it is powered by RemObjects Oxygene". Archived from the original on 2011-12-27. Retrieved 2011-12-14.
  3. ^ "Prism XE4, Where Art Thou? | RemObjects Blogs". Archived from the original on 2013-06-20. Retrieved 2013-06-06.
  4. ^ "Operator Overloading - Delphi Prism". Archived from the original on 2011-07-08. Retrieved 2010-01-09.
  5. ^ "Built-In Types - Delphi Prism". Archived from the original on 2011-07-08. Retrieved 2010-01-10.
  6. ^ "Provide Mixin-like functionality - Delphi Prism". Archived from the original on 2011-07-08. Retrieved 2010-01-17.
  7. ^ "A Stack Overflow discussion where people remark that Oxygene is not Delphi Win32". Archived from the original on 2012-10-25. Retrieved 2016-07-25.
  8. ^ "Delphi Prism 2010 review where they state in the third paragraph that VCL.net is not available". Archived from the original on 2009-09-04. Retrieved 2009-12-14.

Read other articles:

Pour les articles homonymes, voir Love. Love Love dans les années 1960.Informations générales Pays d'origine États-Unis Genre musical Rock psychédélique[1], folk rock[2], acid rock[3], pop psychédélique[4] Années actives 1966–1973, 2002–2005, depuis 2009 Labels Elektra Records, Blue Thumb Records, Harvest Records, RSO Records, Rhino Records, Sundazed Records, Big Beat Records Site officiel love-revisited.com Composition du groupe Membres Johnny EcholsMike RandleDavid GreenDavid C...

  لمعانٍ أخرى، طالع جون هنت (توضيح). هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2019) جون هنت معلومات شخصية تاريخ الميلاد سنة 1900[1][2]  تاريخ الوفاة سنة 1976 (75–76 سنة)[1][2]  مواطنة أيرل...

Parti Melayu Semangat 46S46 PresidenTengku Razaleigh HamzahSekretaris JenderalSuhaimi KamaruddinDeputi PresidenRais YatimKetua PemudaIbrahim Ali (1989-1991)[1]Ketua WanitaHajjah Rahmah Osman[1]Dibentuk3 Juni 1989Dibubarkan8 Oktober 1996[2]Kantor pusatKuala Lumpur, Malaysia[3]Sayap pemudaPergerakan Pemuda S46[4]Keanggotaan200,000 (1996)Ideologinasionalisme Melayu, Islamisme, KonservatismeAfiliasi nasionalGagasan Rakyat / Angkatan Perpaduan UmmahWarnaKuni...

Ayano YugiriTokoh Engage KissAyano Yugiri dalam animePenciptaAniplexPengisi suaraLynn[1] (Jepang)Suzie Yeung[2] (Inggris)BiodataSpesiesManusiaJenis kelaminPerempuanKerabatAkino Yugiri (Ibu)StatusHidupUsia20+Tinggi Badan165 cmTanggal Lahir2 November Ayano Yugiri (夕桐 アヤノcode: ja is deprecated , Yugiri Ayano) adalah karakter fiktif yang muncul dalam proyek media campuran Engage Kiss dibuat oleh Aniplex. Dia adalah agen elit milik PMC utama AAA Defender Co. Dia adalah pu...

1995 aircraft hijacking All Nippon Airways Flight 857JA8146, the aircraft involved in the hijacking incident seen in 1999 at Haneda Airport.HijackingDateJune 21, 1995SummaryHijackingSiteHakodate Airport, Hokkaido, JapanAircraftAircraft typeBoeing 747SR-81OperatorAll Nippon AirwaysRegistrationJA8146Flight originTokyo Haneda Airport, JapanDestinationHakodate Airport, JapanOccupants365Passengers350Crew15Fatalities0Injuries2Survivors365 All Nippon Airways Flight 857 was a scheduled flight fr...

.au

.au البلد أستراليا  الموقع الموقع الرسمي  تعديل مصدري - تعديل   au. هو امتداد خاص بالعناوين الإلكترونية (نطاق) للمواقع التي تنتمي لأستراليا.[1][2] تاريخ الاستخدام تم تخصيص اسم النطاق في الأصل من قبل جون بوستل ، مشغل IANA إلى كيفن روبرت إلز من جامعة ملبورن في عام 1986. ب...

1941 film by Frank R. Strayer Blondie in SocietyFilm posterDirected byFrank R. StrayerScreenplay byKaren DeWolfStory byEleanore GriffinBased oncomic strip Blondieby Chic YoungProduced byRobert SparksStarringPenny SingletonArthur LakeLarry SimmsCinematographyHenry FreulichEdited byCharles NelsonMusic byM. W. StoloffProductioncompanyKing Features SyndicateDistributed byColumbia PicturesRelease dateJune 17, 1941Running time76 minutesCountryUnited StatesLanguageEnglish Blondie in Society is a 194...

Themed land at Disney parks This article is about the themed land in Walt Disney Parks and Resorts. For other uses, see Toontown (disambiguation). This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Mickey's Toontown – news · newspapers · books · scholar · JSTOR (September 2022) (Learn how and when to remove thi...

English racing cyclist (born 1985) For other people named Edward Clancy, see Edward Clancy (disambiguation). Ed Clancy OBEClancy in 2019Personal informationFull nameEdward Franklin ClancyBorn (1985-03-12) 12 March 1985 (age 38)[1]Barnsley, South Yorkshire, EnglandHeight1.86 m (6 ft 1 in)[1]Weight78 kg (172 lb)[1]Team informationCurrent teamRetiredDisciplinesRoadTrackRoleRiderRider typeEnduranceAmateur teams2005–2006Sparkas...

1947 play by Jean Genet For the 1974 film adaptation, see The Maids (film). Les BonnesWritten byJean GenetDate premieredApril 17, 1947 (1947-04-17)Place premieredThéâtre de l'AthénéeParisOriginal languageFrench The Maids (French: Les Bonnes) is a 1947 play by the French dramatist Jean Genet. It was first performed at the Théâtre de l'Athénée in Paris in a production that opened on 17 April 1947, which Louis Jouvet directed.[1] The play by the Maribor Slovene Nat...

Збройні сили Лівану الجيش اللبناني Емблема збройних сил ЛівануГасло شرف · تضحية · وفاء Честь. Жертовність. Відданість Засновані 1 серпня 1945Види збройних сил сухопутні війська,військово-морські сили,повітряні сили.Історія Арабо-ізраїльська війна (1947—1949)Громадянська вій...

Cet article est une ébauche concernant l’éducation. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. IRA de Lille Les écoles de la fonction publique française (EFPF) ont toute la même caractéristique d'assurer la sélection, la formation initiale ainsi que la formation continue des futurs fonctionnaires de l'État, des collectivités territoriales ou de la fonction publique hospitalière. Il existe plusieu...

Nicaraguan baseball player (born 1986) Baseball player Everth CabreraCabrera with the Baltimore OriolesShortstopBorn: (1986-11-17) November 17, 1986 (age 37)Nandaime, NicaraguaBatted: SwitchThrew: RightMLB debutApril 8, 2009, for the San Diego PadresLast MLB appearanceJune 4, 2015, for the Baltimore OriolesMLB statisticsBatting average.246Home runs12Runs batted in132Stolen bases138 Teams San Diego Padres (2009–2014) Baltimore Orioles (2015) Career highligh...

Traditional Music of Sindh. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Sindhi music – news · newspapers · books · scholar · JSTOR (May 2022) (Learn how and when to remove this template message) Music of Pakistan Genres Classical Semi-classical Folk Ghazal Qawwali Sufi Specific forms Religious music Hamd...

الحرب البولندية الروسية لعام 1792   التاريخ وسيط property غير متوفر. بداية 18 مايو 1792  نهاية 27 يوليو 1792  الموقع الكومنولث البولندي الليتواني  تعديل مصدري - تعديل   الحرب البولندية الروسية وقعت الحرب البولندية الروسية عام 1792 (أيضًا، حرب التقسيم الثاني، وفي المصادر البو...

Saint AchilliusMosaic in Hosios LoukasBishop of LarissaBorn3rd centuryDiedAD 330Larissa, ThessalyVenerated inEastern Orthodox Church Catholic ChurchMajor shrinethe island of St. Achillius in Small Prespa Lake, GreeceFeast15 MayPatronageLarissa Saint Achillius of Larissa, also known as Achilles,[1] Ailus,[2] Achillas,[1] or Achilius[3] (Greek: Άγιος Αχίλλειος, Ágios Achílleios) (died 330 AD), was a 4th century bishop of Larissa and one of th...

Latin expression etc. and etcetera redirect here. For other uses, see ETC (disambiguation) and Etcetera (disambiguation). The &c (et ceterarum, Protector of England, Scotland and Ireland and another) shows that Oliver Cromwell did not renounce the English claims on France Et cetera (English: /ɛtˈsɛtərə/ or [proscribed] English: /ɛkˈsɛtərə/, Latin: [ɛt ˈkeːtɛra]), abbreviated to etc., etc, et cet., &c. or &c[1][2] is a Latin expression that is ...

2015 film by Gregory Jacobs Magic Mike XXLTheatrical release posterDirected byGregory JacobsWritten byReid CarolinProduced by Nick Wechsler Gregory Jacobs Channing Tatum Reid Carolin Starring Channing Tatum Matt Bomer Joe Manganiello Kevin Nash Adam Rodríguez Gabriel Iglesias Amber Heard Donald Glover Andie MacDowell Elizabeth Banks Jada Pinkett Smith CinematographySteven Soderbergh[a]Edited bySteven Soderbergh[b]Productioncompanies Iron Horse Entertainment RatPac-Dune Entert...

Greek molecular biologist Stavroula MiliAlma materNational and Kapodistrian University of Athens (BS)Icahn School of Medicine at Mount Sinai (PhD)Scientific careerFieldsMolecular biology, cancer researchInstitutionsNational Cancer InstituteDoctoral advisorSerafin Piñol-Roma [Wikidata] Stavroula Voula Mili is a Greek molecular biologist researching the regulation, functional consequences, and disease associations of localized RNAs. She is a NIH Stadtman Investigator at the N...

Series of portable media players by Sony This article is about the Walkman brand. For information about the generic item, see Personal stereo. For the album by Bad Bad Hats, see Walkman (album). WalkmanWalkman logo since 2000Left to right from top: an (original) cassette Walkman (1980s), a CD Walkman (2001), an MD Walkman (1998), a digital Walkman (2011)ManufacturerSony CorporationTypePortable audio players and recordersLifespanJuly 1, 1979[1] – presentUnits sold385 million (all edi...

Kembali kehalaman sebelumnya