Home > Apple, Obj-C, Programming, Tech > Objective-C vs. Delphi: Syntax

Objective-C vs. Delphi: Syntax

Taken from here.

I’ve also found http://iosdevelopertips.com/ to be a very useful website learning Objective-C.

Objective-C vs. Delphi: Syntax

Objective-C

Delphi

@interface Rectangle: GeometricObject
   {
     @private
     float with;
     float height;
   }

   +(void)aClassMethod;
   -(id)init;
   -(id)dealloc;
   -(void)setSize:(float)aWidth:(float)aHeight;

@end
interface
 
type
  Rectangle = class(GeometricObject)
    private
      width: extended;
      height: extended;
    public
      constructor create; virtual;
      destructor destroy;
      class aClassMethod; virtual;
      procedure setSize(aWidth,
         aHeight: extended); virtual;
     
  end;


implementation

class procedure Rectangle.aClassMethod;
begin
  ...
end;
 
constructor Rectangle.create;
begin 
  inherited create;
  width:=0; 
  height:=0;
end;
 
destructor Rectangle.destroy;
begin
  ...
  inherited destroy;
end;
 
procedure Rectangle.setSize(aWidth, aHeight: extended);
begin
  width:=aWidth;
  height:=aHeight;
end;
 
end.
#import "Rectangle.h"
 
@implementation Rectangle
 
+(void)aClassMethod
{
  ...
}
 
-(id)init
{
  [super init];
  width=0;
  height=0;
  return self;
}
 
-(id)dealloc
{
  ...
  [super dealloc]
}
 
-(void)setSize:(float)aWidth:(float)aHeight
{
   width=aWidth;
   height=aHeight;
}
 
@end
#include <Rectangle.h>
 
void main()
{
   id anyObject;
   Rectangle *aRect;
 
   anyObject = [[Rectangle alloc] init];
   [anyObject setSize:1:2]; // this is
                               dynamic!
 
   if ([anyObject respondsTo:
         @selector(setSize::)])
     [anyObject setSize:1:2]; // this is save!
   

   aRect = [[Rectangle alloc] init];
   [aRect setSize:10:5];
 
 
  [aRect free];
  [aRect free];
 
  exit (0); 
}
uses rectangle.pas;
 
var
  anyObject: TObject;
  aRect: Rectangle;
 
begin
  anyObject:=Rectangle.create;
  // anyObject.setSize(1,2);  NOT POSSIBLE!
 
  aRect:=Rectangle.create;
  aRect.setSize(10,5);
 
  aRect.free;
  anyObject.free;
 
  halt(0);
 
end.
Advertisements
Categories: Apple, Obj-C, Programming, Tech
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s