Difference between revisions of "Talk:FPC PasCocoa"

From Free Pascal wiki
Jump to navigationJump to search
Line 10: Line 10:
  
  
'''Goals'''
+
 
 +
== Goals ==
 +
 
  
 
[[Can someone summarize the goals of what are (and are not) being discussed currently?]]   
 
[[Can someone summarize the goals of what are (and are not) being discussed currently?]]   
Line 22: Line 24:
 
* Objective C 1.0 bindings - NOT
 
* Objective C 1.0 bindings - NOT
  
*[[*** Are we talking about just implementing single calls or are we shooting for semi full framework support so one can use Cocoa event and window handling?]]
+
*[[*** Are we talking about just implementing single calls or are we shooting for semi full framework support so one can use Cocoa event and window handling?  From reading further on, it looks like we are just worrying about the programmer implementing one function at a time as needed?]]
  
 
[[ Any more goals?]]
 
[[ Any more goals?]]
Line 28: Line 30:
  
  
How does anything here affect the existing PasCocoa with Objective C 1.0 binding work?
+
== Current PasCocoa Implementation ==
 +
 
 +
Currently PasCocoa is supported as ObjFPC wrapper classes. You can learn more about it at this page PasCocoa
 +
 
 +
 
 +
== How does anything decided or implemented here affect the existing PasCocoa with Objective C 1.0 binding work ==
 +
 
 +
Using wrapper classes is generally difficult because it demands the programmer have some knowledge about the wrappers' implementation.
 +
For example, it must be remembered, that a wrapper object needs to be created to use Objective C object . If object's "id" reference is not passed as a Handle to the wrapper's constructor, it should be assigned in some other way, otherwise, wrappers will fail to execute properly.
 +
 
 +
[[Are there other specific issues which can be mentioned?]]
 +
 
 +
If the compiler can take care of some or all of the translation and mapping issues, implementing Objective C Classes/objects is much easier to implement.  If the Objective C runtime API is available and interfaced to,  it is possible for any language to work with objective-c classes and objects.
 +
 
 +
 
 +
== Proposed Compiler Syntax ==
 +
 
 +
=== Class declaration ===
 +
 
 +
To declare an FPC Class for an external objective-c class, the keyword "ObjCClass" would be introduced.
 +
Objective-C classes must be declared individually (as any other Pascal type in the interface section of the unit)  [[Unless a new RTL unit is created?]] 
 +
For example:
 +
 
 +
  type
 +
    YourClassName =  ObjCClass [(ObjCSuperClassName [, ProtocolName, ProtocolName])] [external]
 +
      [variables declarations]
 +
      [method declarations]
 +
    end;
 +
 
 +
ObjCClass - defines an Objective C class type declaration
 +
 
 +
ObjCSuperClassName - identifies an optional [[external objective C?]]  parent (or super) class for the class. If the superclass name is not specified, it's considered that type inherits from the base objective C class, ''NSObject''
 +
 
 +
external - Objective-C class declaration. This is necessary to distinguish a class that's implemented by an external, non FPC supplied framework or library (which is from Cocoa in this case) from regular Pascal routines implemented in an FPC user written unit . The Pascal type is declared in the interface of the unit, and the class is implemented in the external framework.  [[Do we need to write anything in the implementation section of the unit or will this be handled automatically without having to write anything there?]]
 +
 
 +
=== Method declaration ===
 +
 
 +
In general, Objective C methods are declared the same way regular pascal class methods are declared.  The [[only?]] exception is that each Objective C Class  method must also have an additional '''messaging''' name specified.  Example:
 +
 
 +
 
 +
  AnotherObject = ObjCClass(NSObject)
 +
    procedure aMethodName ( params: Integer); message 'aMethodName:'; 
 +
  end;
 +
 
 +
 
 +
each ObjCClass method name  is followed by keyword '''message''', and the '''message''' keyword is followed by a string constant that matches an existing Objective C method name.  [[So, this means, you will only be able to use a subset of all the possible methods available from the actual underlying Objective C Class = those specific methods you specifically declare?]]
 +
 
 +
 
 +
If the method name is preceeded with keyword '''class''', it signifies that the method is an ObjCClass method (marked as preceeding "+" at objective-c), rather than instance method (marked as preceeding "-")  [[Need an example of this syntax.  Not sure what you are saying here or how this is different than the above declaration]]
 +
 
 +
 
 +
'Note: it's common for an objective-c method name/identifier to begin with a lower case letter.  It is recommended that PasCocoa objects declared in an FPC program follow the same convention.
  
  

Revision as of 05:57, 8 March 2009

There is interest in expanding support in FPC for coding applications for the Macintosh platform which can incorporate the Cocoa framework. Some work has already been accomplished in this area and some other discussions have begun weighing potential compiler support. This wiki page is an attempt to summarize the discussions and issues surrounding the support and implementation concerns. The intent is to maintain this page as an up to date reference for open and resolved issues so avoid repetitive questions and having to wade through previous mailing list posts.

If you are able to absolutely clarify or add to anything written on this page, please go ahead and make any corrections or additions directly on this page. If you are unsure of anything, please post your thoughts or questions to the MacPascal mailing list or add them to the "Discussion" page for this article. If you think something is missing in this page, go ahead and add it as an underlined/red question and notify the mailing list of it and hopefully someone or yourself will enter the appropriate text (deleting the question from the page in the process.) If this seems to be too many guidelines they are only meant to facilitate things and keeping some semblance of order and not meant to get in the way of getting things done :) If anyone can improve the process, feel free to voice their constructive opinion :)

Everyone is welcome to participate. Thank you for your interest and support of this project.

to subscribe to the MacPascal mailing list : http://lists.sonic.net/mailman/listinfo/mac-pascal

to post a message to the mailing list : Mac-Pascal@listman.sonic.net


Goals

Can someone summarize the goals of what are (and are not) being discussed currently?

  • Compiler support to make it easier and more transparent for declaring and implementing an FPC Class to map to an Objective C Class. (2.0 Bindings)
  • A new RTL interface unit containing a number of basic/useful Objective C Classes (which would expand as effort permits) ***
  • Interface Builder Support - NOT
  • Objective C 1.0 bindings - NOT
  • [[*** Are we talking about just implementing single calls or are we shooting for semi full framework support so one can use Cocoa event and window handling? From reading further on, it looks like we are just worrying about the programmer implementing one function at a time as needed?]]

Any more goals?


Current PasCocoa Implementation

Currently PasCocoa is supported as ObjFPC wrapper classes. You can learn more about it at this page PasCocoa


How does anything decided or implemented here affect the existing PasCocoa with Objective C 1.0 binding work

Using wrapper classes is generally difficult because it demands the programmer have some knowledge about the wrappers' implementation. For example, it must be remembered, that a wrapper object needs to be created to use Objective C object . If object's "id" reference is not passed as a Handle to the wrapper's constructor, it should be assigned in some other way, otherwise, wrappers will fail to execute properly.

Are there other specific issues which can be mentioned?

If the compiler can take care of some or all of the translation and mapping issues, implementing Objective C Classes/objects is much easier to implement. If the Objective C runtime API is available and interfaced to, it is possible for any language to work with objective-c classes and objects.


Proposed Compiler Syntax

Class declaration

To declare an FPC Class for an external objective-c class, the keyword "ObjCClass" would be introduced. Objective-C classes must be declared individually (as any other Pascal type in the interface section of the unit) Unless a new RTL unit is created? For example:

 type
   YourClassName =  ObjCClass [(ObjCSuperClassName [, ProtocolName, ProtocolName])] [external]
     [variables declarations]
     [method declarations]
   end;

ObjCClass - defines an Objective C class type declaration

ObjCSuperClassName - identifies an optional external objective C? parent (or super) class for the class. If the superclass name is not specified, it's considered that type inherits from the base objective C class, NSObject

external - Objective-C class declaration. This is necessary to distinguish a class that's implemented by an external, non FPC supplied framework or library (which is from Cocoa in this case) from regular Pascal routines implemented in an FPC user written unit . The Pascal type is declared in the interface of the unit, and the class is implemented in the external framework. Do we need to write anything in the implementation section of the unit or will this be handled automatically without having to write anything there?

Method declaration

In general, Objective C methods are declared the same way regular pascal class methods are declared. The only? exception is that each Objective C Class method must also have an additional messaging name specified. Example:


 AnotherObject = ObjCClass(NSObject)
   procedure aMethodName ( params: Integer); message 'aMethodName:';   
 end;


each ObjCClass method name is followed by keyword message, and the message keyword is followed by a string constant that matches an existing Objective C method name. So, this means, you will only be able to use a subset of all the possible methods available from the actual underlying Objective C Class = those specific methods you specifically declare?


If the method name is preceeded with keyword class, it signifies that the method is an ObjCClass method (marked as preceeding "+" at objective-c), rather than instance method (marked as preceeding "-") Need an example of this syntax. Not sure what you are saying here or how this is different than the above declaration


'Note: it's common for an objective-c method name/identifier to begin with a lower case letter. It is recommended that PasCocoa objects declared in an FPC program follow the same convention.



How about adding a section like this?

Objective C & Cocoa Information

---maybe a paragraph or two on how Objective C declares classes,objects and methods. Then maybe a paragraph on the Cocoa framework and an example of a typical Cocoa class in Obj C. ?

Then some links to more detailed ObjC/Cocoa information --snipped from the mailing list


http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html

Everyone going into Cocoa pogramming would be well served reading this guide. The Cocoa class reference is in great majority of cases silent about what you are expected to do with regards to object ownership with instances that you obtain from the system, since authors expected us to read and understand above document. Only exceptions are documented. Sorry about sounding obnoxious, but on cocoa-dev mailing list there are at least 2 threads every month about crashes or leaks, because people didn't read, or have just skimped this guide. nice reading, - Gorazd


For all that are working with Cocoa it is mandatory to review:

http://www.stepwise.com/Articles/Technical/2001-03-11.01.html

http://www.stepwise.com/Articles/Technical/HoldMe.html

Despite it is written in 2001, it is still a relevant document describing memory management rules and owneship of objects that are valid unless you use Objective-C garbage collection. -Gorazd


And general ObjC and Cocoa Documentation? -- suggestions welcome :)

http://developer.apple.com/documentation/Cocoa/ObjectiveCLanguage-date.html

http://developer.apple.com/referencelibrary/API_Fundamentals/Cocoa-fund-date.html

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/chapter_2_section_1.html#//apple_ref/doc/uid/TP40002974-CH3