Quickly Learn To Use Delphi Classes To Create A New Python Type With Python4Delphi Sample App
import spam
p = spam.CreatePoint(2, 5)
print (p)
p.OffsetBy( 3, 3 )
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”)
p = spam.CreatePoint(2, 5)
try:
print (“raising an error of class EBadPoint”)
p.RaiseError() # it will raise spam.EBadPoint
except spam.PointError as what: #it shows you 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)
# 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: #it shows you 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.CreatePoint(2, 5):
print (“Equal”)
else:
print (“Not equal”)