Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-03

Layout of class method

13 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

I'd just like to confirm. Considering the following class method:

{$mode delphi}
interface
type
  TMyController = class(NSObject)
  public
    class function
applicationShouldTerminateAfterLastWindowClosed(param1: objc.id;
     param2: SEL; theApplication: objc.id): cbool; cdecl;
  end;

---
Does it have the exact same layout as the procedure bellow? i.e. without hidden Self parameter.

function  applicationShouldTerminateAfterLastWindowClosed(param1: objc.id;
     param2: SEL; theApplication: objc.id): cbool; cdecl;

thanks,

Felipe Monteiro de Carvalho

Reply by email

Jonas Maebe
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 22 lines
I'd just like to confirm. Considering the following class method: {$mode delphi} interface type TMyController = class(NSObject) public class function applicationShouldTerminateAfterLastWindowClosed(param1: objc.id; param2: SEL; theApplication: objc.id): cbool; cdecl; end; --- Does it have the exact same layout as the procedure bellow? i.e. without hidden Self parameter. function applicationShouldTerminateAfterLastWindowClosed(param1: objc.id; param2: SEL; theApplication: objc.id): cbool; cdecl;

Unlikely (afaik there is a hidden VMT pointer), and even if it did, it would not be guaranteed to remain that way. To be able to interface Objective-C code in an OOP way in FPC, support for some kind of Objective Pascal dialect has to be added to the compiler. Everything will probably break at one time or another.

Jonas

Reply by email

Felipe Monteiro de Carvalho
to Jonas Maebe
Jonas Maebe wrote
To be able to interface Objective-C code in an OOP way in FPC, support for some kind of Objective Pascal dialect has to be added to the compiler. Everything will probably break at one time or another.

Ummm ... I'd like to keep compiler and sintax changes to absolute minimal. Ideally zero like now =P and I'm very close of having a fully object-oriented interface to objective-c.

Alternatively maybe an extra method modifier could be easier to implement then a new dialect. One that guarantees that no hidden VTM parameter is on the method ... but I'm almost sure there is already some way of achieving that ...

Another idea is having a objcclass type of class, which can handle automatically some of the work currently done on the bindings, but I'd rather avoid that as it's hard for me to develop it.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Jonas Maebe
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 15 lines
On Wed, Mar 12, 2008 at 6:10 AM, Jonas Maebe < > wrote: > To be able to interface > Objective-C code in an OOP way in FPC, support for some kind of > Objective Pascal dialect has to be added to the compiler. Everything > will probably break at one time or another. Ummm ... I'd like to keep compiler and sintax changes to absolute minimal. Ideally zero like now =P and I'm very close of having a fully object-oriented interface to objective-c. Alternatively maybe an extra method modifier could be easier to implement then a new dialect. One that guarantees that no hidden VTM parameter is on the method ... but I'm almost sure there is already some way of achieving that ...

In theory, declaring a class method as static should do that (as mentioned before either here or on fpc-devel), but it doesn't at this time. Feel free to file a bug.

Jonas

Reply by email

Jonas Maebe
to Felipe Monteiro de Carvalho: Ummm ... I'd like to keep compiler and sintax changes to absolute minimal. Ideally zero…
Felipe Monteiro de Carvalho wrote
Ummm ... I'd like to keep compiler and sintax changes to absolute minimal. Ideally zero like now =P and I'm very close of having a fully object-oriented interface to objective-c.

Aren't you going to have problems with memory leaks with these wrapper instances? Suppose you create an instance in Pascal code, then pass the (wrapped) Objective-C class instance to an Objective-C method which releases it -> how will the Pascal wrapper instance ever be released? (and if the programmer frees it himself, how can you avoid sending a release message to the already released instance?)

Jonas

Reply by email

Felipe Monteiro de Carvalho
to Jonas Maebe
Jonas Maebe wrote 5 lines
Aren't you going to have problems with memory leaks with these wrapper instances? Suppose you create an instance in Pascal code, then pass the (wrapped) Objective-C class instance to an Objective-C method which releases it -> how will the Pascal wrapper instance ever be released?

I don't know any example of a method in Cocoa which may or not release the class depending on something. If it surely frees the class, then you can set MyObject.Handle to nil before freeing it. Else there exists no problem.

I'm building a nice way to create Cocoa apps in Pascal, not a generic object-oriented objective-c bridge.

The main aim is creating a Lazarus-Cocoa widgetset, and maybe adding some Cocoa to the LCL-Carbon widgetset to get TTrayIcon implemented.

I personally consider my bindings good enougth to be used to create pure Cocoa applications, but I have no need to develop Cocoa specific applications.

Felipe Monteiro de Carvalho

Reply by email

Felipe Monteiro de Carvalho
to Jonas Maebe: In theory, declaring a class method as static should do that (as mentioned before either…
Jonas Maebe wrote
In theory, declaring a class method as static should do that (as mentioned before either here or on fpc-devel), but it doesn't at this time. Feel free to file a bug.

What is the syntax of a class method on FPC?

I did a search and the syntax on delphi seams to be this:

class procedure SetClassProperty(Value: Integer); static;

But my FPC 2.2.0 doesn't recognize the "static" at the end of the declaration. I read the other thread, but there is nothing there that makes the syntax clear.

Maybe isn't of having wrongly implemented static methods, fpc simply doesn't have them yet?

thanks,

Felipe Monteiro de Carvalho

Reply by email

Michael Van Canneyt
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 10 lines
On Wed, Mar 12, 2008 at 3:43 PM, Jonas Maebe wrote: > In theory, declaring a class method as static should do that (as > mentioned before either here or on fpc-devel), but it doesn't at this > time. Feel free to file a bug. What is the syntax of a class method on FPC? I did a search and the syntax on delphi seams to be this: class procedure SetClassProperty(Value: Integer); static;

No.
You must not specify the static. Where did you get that from ?

Michael.

Reply by email

Jonas Maebe
to Felipe Monteiro de Carvalho: What is the syntax of a class method on FPC? I did a search and the syntax on delphi…
Felipe Monteiro de Carvalho wrote 15 lines
On Wed, Mar 12, 2008 at 3:43 PM, Jonas Maebe < > wrote: > In theory, declaring a class method as static should do that (as > mentioned before either here or on fpc-devel), but it doesn't at this > time. Feel free to file a bug. What is the syntax of a class method on FPC? I did a search and the syntax on delphi seams to be this: class procedure SetClassProperty(Value: Integer); static; But my FPC 2.2.0 doesn't recognize the "static" at the end of the declaration. I read the other thread, but there is nothing there that makes the syntax clear.

You have to use the -St command line option for the "static" keyword to be recognised.

Jonas

Reply by email

Felipe Monteiro de Carvalho
to Michael Van Canneyt: What is a 'static' class method ? D7 does not know them. Michael.
Michael Van Canneyt wrote
What is a 'static' class method ? D7 does not know them.

I think it was introduced after D7. C# also seams to have this concept, so I think it's somehow related to .NET on the delphi implementation, but it's also available for delphi-win32 and now I'm giving it a completely new use =) (objc interfacing)

Felipe Monteiro de Carvalho

Reply by email