Ultra-Fast Way To Wrap Delphi Objects To Python Objects With Python4Delphi Sample App

import spam

 

class MyPoint(spam.Point):

  def Foo(Self, v):

    Self.OffsetBy(v, v)

 

p = spam.Point(2, 5)

print (p, type(p))

p.OffsetBy( 3, 3 )

print (p.x, p.y)

print (“Name =”, p.Name)

p.Name = ‘Hello world!’

print (“Name =”, p.Name)

 

p = spam.Point(2, 5)

print (p, type(p))

p.OffsetBy( 3, 3 )

print (p.x, p.y)

 

# create a subtype instance

p = MyPoint(2, 5)

print (p, type(p))

p.OffsetBy( 3, 3 )

print (p.x, p.y)

p.Foo( 4 )

print (p.x, p.y)

print (dir(spam))

print (spam.Point)

print (“p = “, p, ”  –> “,)

if type(p) is spam.Point:

  print (“p is a Point”)

else:

  print (“p is not a point”)

p = 2

print (“p = “, p, ”  –> “,)

if type(p) is spam.Point:

  print (“p is a Point”)

else:

  print (“p is not a point”)

 

# You can raise errors from a Python script too !

print (“——————————————————————“)

print (“Errors in a Python script”)

try:

  raise spam.EBadPoint(“this is a test !”)

except:

  pass

 

try:

  err = spam.EBadPoint()

  err.a = 1

  err.b = 2

  err.c = 3

  raise err

except spam.PointError as what: # this shows that you can intercept a parent class

  print (“Caught an error derived from PointError”)

  print (“Error class = “, what.__class__, ”     a =”, what.a, ”   b =”, what.b, ”   c =”, what.c)

 

if p == spam.Point(2, 5):

  print (“Equal”)

else:

  print (“Not equal”)