freelanceprogrammers.org Forum Index » Delphi

Python bool represented in delphi


View user's profile Post To page top
larsen_roar Posted: Mon Oct 17, 2005 4:38 pm


Joined: 12 Aug 2005

Posts: 7
Python bool represented in delphi
Hi,
 
I`ve just upgraded P4D from 3.27 to 3.29 (currently using Delphi 5)
 
In my app I have a tag database accessible from python with SetValue(tagname,value) and GetValue(tagname)
(all values are represented by double`s inside the delphi app)
 
With P4D 3.27 SetValue(tagname,True) sets the tagdatabase value to 1, while P4D 3.29 sets the value to -1
(equals Ord(True) in Delphi).
 
In the P4D history I notices :
 




Version 3.28 (avr. 23, 2005)





Fixed a bug in PyObjectAsVariant thanks to Kiriakos Vlahos [kvlahos@...]Testing for Boolean values should be done before Integer values, as Boolean inherit from Integers.
Is this "new" behaviour related to the above change (causes script statements "if val==1:" has to be rewritten to "if val<>0:" which actually is
a better syntax for bool evaluations but unfortunely causes misbehaved scripts for our customers....) ?
 
Roar Larsen--------------------------------------------------------------------------------------TORDIVEL ASLade Alle 65 C, N-7041 Trondheim, NorwayTel : +47 7350 9220 Fax : + 47 2315 8701E-mail : roar@... Web : http://www.tordivel.no--------------------------------------------------------------------------------------...... THE VISION SOFTWARE HOUSE--------------------------------------------------------------------------------------
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Sun Oct 23, 2005 10:06 pm


Joined: 29 Apr 2005

Posts: 103
Python bool represented in delphi
Hi Roar,

> I`ve just upgraded P4D from 3.27 to 3.29 (currently using Delphi 5)
>
> In my app I have a tag database accessible from python with
SetValue(tagname,value) and GetValue(tagname)
> (all values are represented by double`s inside the delphi app)
>
> With P4D 3.27 SetValue(tagname,True) sets the tagdatabase value to
1, while P4D 3.29 sets the value to -1
> (equals Ord(True) in Delphi).
>
> In the P4D history I notices :
>
> Version 3.28 (avr. 23, 2005)
>
> a.. Fixed a bug in PyObjectAsVariant thanks to Kiriakos
Vlahos [kvlahos@l...]
> Testing for Boolean values should be done before Integer
values, as Boolean inherit from Integers.
>
>
> Is this "new" behaviour related to the above change (causes script
statements "if val==1:" has to be rewritten to "if val<>0:" which
actually is
> a better syntax for bool evaluations but unfortunely causes
misbehaved scripts for our customers....) ?

Your SetValue function will invoke PyObjectAsVariant, which will
detect the boolean Python value and convert it into a proper boolean
variant, which will then be casted to an integer as -1.
So, you`re right!
To avoid this side effect, simply rewrite your SetValue function to
detect the type of value and if it`s True or False, then convert it
to your expected integer value (from Delphi, you can compare the
object to Py_True and Py_False).
You can also rename your SetValue function to _SetValue and define a
new Python function like this:
def SetValue(tagname, value):
if value is True:
value = 1
elif value is False:
value = 0
_SetValue(tagname, value)


VariantAsPyObject was not changed since 3.27.

Bye,

Morgan
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help