FPC PasCocoa/Differences

From Lazarus wiki
Revision as of 19:06, 26 August 2009 by Jonas (talk | contribs) (New page: =Introduction= FPC's "Objective-Pascal" (ObjCPas) dialect was introduced to enable seamless interfacing with Objective-C code, in particular on Mac OS X. Due to inhe...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

FPC's "Objective-Pascal" (ObjCPas) dialect was introduced to enable seamless interfacing with Objective-C code, in particular on Mac OS X. Due to inherent differences between the C and Pascal philosophies, this language mode will have some seemingly strange behaviour regardless of whether your main background is in Objective-C or in Object-Pascal.

This page describes the conceptual differences between ObjCPas and on the one hand Objective-C, and on the other hand Object Pascal.

Differences with Object Pascal

No constructors

  • Description: The Objective-C language has no notion of a formal constructor. Hence, the constructor keyword is not supported in an objcclass.
  • What to do: Construction of class instances in Objective-C usually happens explicitly in two stages: first the alloc class message is sent to the class type that you want to instantiate, and next you send an initXXX instance message to its result. This initXXX (with XXX dependent on the class type) message is called an initializer, and will initialise in the various fields.
  • More information: http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html

No unique root class

  • Description: In Object Pascal, if you do not specify a parent class, a newly defined class will automatically inherit from TObject. While in NeXTStep/Apple/GNUStep's Objective-C frameworks NSObject fulfills a similar role, there are also other root classes (such as NSProxy). Since there is no unique root class in the Objective-C language, this means that if you do not specify a parent class, you will define a new root class.
  • What to do: Generally, you will want new classes to inherit from NSObject if they do not have to inherit from any other class.