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.