Objective-C to Delphi bridge

Hi,

Can someone explain the Wrap and OCCClass stuff?
Is there a document or article that explains how we access Objective-C methods and vice-versa?

It's a little confusing to me right now.

Any info would be appreciated.

Thanks,
Joe
0
Joe
8/1/2013 7:59:40 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

2 Replies
1195 Views

Similar Articles

[PageSpeed] 39

Joe Sansalone wrote:

> Hi,
> 
> Can someone explain the Wrap and OCCClass stuff?
> Is there a document or article that explains how we access
> Objective-C methods and vice-versa?

If you must access an NSObject derivate (all Cocoa classes, etc.), you
wrap them to get an interface with the name of the class. You can then
call the instance methods like normal interface methods. To get at
class methods, you call OCClass.

  So TNSColor.Wrap(someInstance)

gets you an interface of type NSColor with the desired methods. But to
call a class method, like blackColor, you call
TNSColor.OCClass.blackColor. This returns an instance, so you wrap it
to get an interface for it.

The methods are, as far as I can see, being resolved by RTTI, so if you
write an object of your own, say, a delegate, it is very important how
you name your parameters. The names of parameters (except the first
one) are used to construct the selector for the method.

So to implement a method
  
  getString:withLength:andEncoding:

you declare it:

  function getString(s: NSString; withLength: integer; andEncoding:
NSStringEncoding);

So the parameter names become the trailing parts of the method name.

-- 
Rudy Velthuis (TeamB)    http://www.teamb.com

"It is dangerous to be right when the government is wrong."
 -- Voltaire
0
Rudy
8/2/2013 7:45:01 AM
> {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> Joe Sansalone wrote:
> 
> > Hi,
> > 
> > Can someone explain the Wrap and OCCClass stuff?
> > Is there a document or article that explains how we access
> > Objective-C methods and vice-versa?
> 
> If you must access an NSObject derivate (all Cocoa classes, etc.), you
> wrap them to get an interface with the name of the class. You can then
> call the instance methods like normal interface methods. To get at
> class methods, you call OCClass.
> 
>   So TNSColor.Wrap(someInstance)
> 
> gets you an interface of type NSColor with the desired methods. But to
> call a class method, like blackColor, you call
> TNSColor.OCClass.blackColor. This returns an instance, so you wrap it
> to get an interface for it.
> 
> The methods are, as far as I can see, being resolved by RTTI, so if you
> write an object of your own, say, a delegate, it is very important how
> you name your parameters. The names of parameters (except the first
> one) are used to construct the selector for the method.
> 
> So to implement a method
>   
>   getString:withLength:andEncoding:
> 
> you declare it:
> 
>   function getString(s: NSString; withLength: integer; andEncoding:
> NSStringEncoding);
> 
> So the parameter names become the trailing parts of the method name.
> 
> -- 
> Rudy Velthuis (TeamB)    http://www.teamb.com
> 
> "It is dangerous to be right when the government is wrong."
>  -- Voltaire


Thank you.  This helped clarify what was going on with all these Wrap and OCClass calls.

Joe
0
Joe
8/2/2013 2:50:06 PM
Reply:

Similar Artilces:

I have Delphi 2010 which includes c++, but it always loads as Delphi
Hi there, I have Delphi 2010 which includes c++, but it always loads as Delphi. How do I forced to load as c++? Thanks for the help Jorge <Jorge Uriarte> wrote in message news:393178@forums.embarcadero.com... > I have Delphi 2010 which includes c++, but it always loads as Delphi. How > do I forced to load as c++? Did you actually install the C++ personality? Are you loading the IDE using the "Delphi 2010" shortcut (which loads bds.exe with the "-pDelphi" command line parameter)? You should be using the "C++Builder 2010" shortcut (...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

RAD Studio 2010 (Delphi, C++Builder, and Delphi Prism) Posted
All, The new roadmap for RAD Studio has been posted. Link: http://edn.embarcadero.com/article/39934 Enjoy, Mike "Michael Rozlog" <michael.rozlog@embarcadero.com> wrote in message news:241286@forums.embarcadero.com... > The new roadmap for RAD Studio has been posted. We have to wait all the way until Commodore to get better documentation? And until Chromium to get OTA documentation? -- Remy Lebeau (TeamB) On 10.05.2010 23:50, Michael Rozlog wrote: > All, > > The new roadmap for RAD Studio has been posted. > > Link: http://e...

RAD Studio 2010 (Delphi, C++Builder, and Delphi Prism) Posted
All, The new roadmap for RAD Studio has been posted. Link: http://edn.embarcadero.com/article/39934 Enjoy, Mike Michael Rozlog wrote: > All, > > The new roadmap for RAD Studio has been posted. > > Link: http://edn.embarcadero.com/article/39934 > Thanks for the info, Mike. One thing I'm missing in the slides is the effort to bring the compiler into the C++ Standard compliance (lamda/closures, auto/decltype, etc.) I hope it's just an omission! :) Il Tue, 11 May 2010 09:01:04 -0700, Alex Bakaev <a@b.cc> ha scritto: >Than...

Help rewrite Objective-C procedure to Delphi
Hello, I found two procedures on Objective-C: {code} - (BOOL)addApplicationToLoginItems:(NSString *)path { NSDictionary *domain = [self persistentDomainForName:@"loginwindow"]; NSArray *apps = [domain objectForKey:@"AutoLaunchedApplicationDictionary"]; NSArray *matchingApps = [apps filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"Path CONTAINS %@", path]]; if ([matchingApps count] == 0) { NSMutableDictionary *newDomain = [domain mutableCopy]; NSMutableArray *newApps = [[apps mutableCopy] autorelease]; ...

Delphi User: Object typecasting in C++ Builder
Hi, I am new in C++ Builder and I need to learn some basic things. I am trying to convert next code from Delphi into C++ code: TNxSpinEdit(NextGrid1.Columns[0].Editor).Max := 200; I have try to convert this code into: (TNxSpinEdit)NextGrid1->Columns->Item[0]->Editor->Max = 200; But this don't work and shows error that Max is not a member of TNxSpinEdit base class What can I do, or how translated code will need to look like. Best regards and thanks Bojan On Thu, 27 Aug 2009 20:37:32 -0700, Bojan Nikolic <> wrote: >I am trying to convert nex...

ANN: WPTools 6.20 for Delphi 5 to Delphi XE2 & C++Builder
WPTools V6.20 is available now. If you work with Delphi or C++Builder our WPTools Version 6 is the perfect text wordprocessing component for You. It is a native VCL Component with all the editing features which are common to powerful wordprocessing applications and wordprocessing controls. With the PRO and Premium License you get 100% object pascal source. WPTools can be used as a powerful word processor and to create programmatically controlled text. It has a very versatile mail-merge feature which can be enhanced with the "WPReporter addon" to also work with bands. So it ...

Protected methods and properties in Objective-C vs Delphi
I'm presently involved in writing an iPhone app and have come against yet another learning curve. Whereas Delphi has good visibility specifiers and easy ways to declare properties and methods as private and protected, Objective-C has traditionally been a tad "imprecise" about visibility :-) For those who fancy a trip into the surreal world that is Objective-C programming, I have written a small article in my own forums - http://carterconsulting.org.uk/forums/viewtopic.php?f=3&t=18 Read it and you might be glad you still have work in Delphi ;-) Joanna ...

Re: Delphi User: Object typecasting in C++ Builder
>Thank you Vladimire, > >Unfortunatelly, I am receiving a compiler error: >Undefined symbol 'polymorphic_downcast' > >I am using CBuilder v6. Maybe this made a problem? Is there maybe a version of this code for CB6? Performance is not a problem. it's a part of boost library. if you don't want to use boost you could wtite simple code template <class Target, class Source> inline Target polymorphic_downcast(Source * x) { V_ASSERT(dynamic_cast<Target>(x)==x); return static_cast<Target>(x); } -- Vladimir Ulchenko aka vava...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Android C demo program to Firemonkey Delphi (Will Pay)
I have a C demo program for the Android platform that I need to convert to Firemonkey and Delphi XE5. This demo logic is written in pure C, and reads one of 5 canned barcodes. Page39a contains those barcodes. The goal is to scan those codes and react accordingly. This conversion will serve as a learning process for me. I am willing to pay for this conversion if need be. Thanking you all in advance and I look forward to any recommendations. Andy http://www.odesk.com/ has developers for hire. Thanks Eli. I will check it out. Andy On Thu, 29 May 2014 06:18:43 -0700, Eli...

C++ to Delphi
How to convert char pSerialNo[] to delphi? Serial:Pchar ??? "John Kadaif" <prevodilac@hotmail.com> wrote in message news:290957@forums.embarcadero.com... > How to convert > char pSerialNo[] > to delphi? It depends on the context in which it is being used. Most C++ compilers do not allow unbounded arrays in most areas of code, but some compilers in some areas do allow it. Can you show a more complete code snippet that shows how pSerialNo is being used exactly? -- Remy Lebeau (TeamB) > {quote:title=John Kadaif wrote:}{quote} > How t...

C/C++ header in delphi project
Hello, I have client dll for comunication with electronic (card with chip) driver license, but manufacturer give me only header for C/C++ and they don't know for Delphi, C#,... So, can I implement .h files into my Delphi projects or is there any solution how to translate this file to pas file for communication with DLL files for those cards. Here is original .h file: // --------------------------------- // #ifndef __eVehicleRegistrationAPI_h__ #define __eVehicleRegistrationAPI_h__ // --------------------------------- #ifndef SD_API #define SD_API extern "C&...

How to use Delphi object embeded in a DLL in a C++Builder app
Hi all, I've written a small DLL in Delphi and a test program in Delphi too and everything works fine but I need to write a C++Builder app that will use the DLL too and I don't know / understand how to get access to the object defined in the DLL. MyDLL.dpr {code} library MyDLL; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies ...

Web resources about - Objective-C to Delphi bridge - embarcadero.delphi.firemonkey

Objective-C - Wikipedia, the free encyclopedia
.h, .m, .mm Objective-C is a general-purpose , object-oriented programming language that adds Smalltalk -style messaging to the C programming ...

How-to articles for iPhone development and Objective-C
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation ...

Beginning Objective C for iPad on the iTunes App Store
Get Beginning Objective C on the App Store. See screenshots and ratings, and read customer reviews.

Apple popularity boosts Objective-C language past C++ - Mobile Development, mobile technology, iPhone ...
Tiobe's language usage index now has the Objective-C language used for building iPad and iPhone apps taking third place, knocking C++ to fourth ...

Stop the funeral! Objective-C is alive and kicking
Objective-C may no longer be the stylish language choice for Apple iOS and Mac OS development that mantle is being assumed by Swift, introduced ...

Adobe Rewriting The Wired iPad App... In Objective C
Remember Wireds iPad app? It might still arrive, but rewritten in Objective C.

Programming with Objective-C: Customizing Existing Classes
Describes elements of best practice when writing code with Objective-C using ARC.

Apple's top secret Swift language grew from work to sustain Objective C, which it now aims to replace ...
... on SwiftApple's surprise new programming language unveiled at WWDCstarted development four years ago in conjunction with efforts to keep Objective ...

Objective-C Programming Language
Holen Sie sich „Objective-C Programming Language“ im App Store. Sehen Sie sich Screenshots, Bewertungen und Kundenrezensionen dazu an.

Basic Unit Testing in Objective-C
... option of creating unit tests, which you can use to verify your code without manual intervention. Here's an example... // IntroductionToObjectiveCTests.m ...

Resources last updated: 1/21/2016 10:25:09 PM