clonly / python4delphi

Automatically exported from code.google.com/p/python4delphi
0 stars 0 forks source link

TPyObject.GetAttr changes from 3.32 to 3.33 (r16) #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've checked out the r16 from svn and my app no longer works.

In my app I've added TPyObject derived classes with attributes and methods 
but I no longer can access the methods added by AddMethod. I've noticed 
that the TPyObject.GetAttr has changed from origin MMM-Experts 3.32 and svn 
3.33 (r16)

3.32:

function  TPyObject.GetAttr(key : PChar) : PPyObject;
begin
  with GetPythonEngine do
    begin
      // check for a method
      Result := Py_FindMethod( PythonType.MethodsData, GetSelf, key);
      if not Assigned(Result) then
        PyErr_SetString (PyExc_AttributeError^, PChar(Format('Unknown 
attribute "%s"',[key])));
    end;
end;

3.33:

function  TPyObject.GetAttr(key : PChar) : PPyObject;
var
  PyKey : PPyObject;
begin
  with GetPythonEngine do
    begin
      PyKey := PyString_FromString(key);
      try
        Result := PyObject_GenericGetAttr(GetSelf, PyKey)
      finally
        Py_XDecRef(PyKey);
      end;

//      // check for a method
//      if IsPython3000 then
//        // I think Python 3000 from beta 2 gets the methods from the 
tp_methods field
//        Result := nil
//      else
//        Result := Py_FindMethod( PythonType.MethodsData, GetSelf, key);
//      if not Assigned(Result) then
//        PyErr_SetString (PyExc_AttributeError^, PChar(Format('Unknown 
attribute "%s"',[key])));
    end;
end;

Can anyone give some info regarding the changes and how to fix my app?

Original issue reported on code.google.com by r...@tordivel.no on 23 Oct 2009 at 7:44

GoogleCodeExporter commented 9 years ago
Can you provide the following info:
-  Version of Python used
-  Version of Delphi used
-  How you defined the attribute that cannot be located

Ideally post a little project that demonstrates the issue. (Expected result vrs
actual result)

Original comment by pyscripter on 6 Dec 2009 at 12:15

GoogleCodeExporter commented 9 years ago
Sorry I read your report and saw that you are using the AddMethod way.  Still a 
demo
reproducing the error would help.  I guess you are using Python 2x.

Original comment by pyscripter on 6 Dec 2009 at 12:23

GoogleCodeExporter commented 9 years ago
Cannot Reproduce.

Take for example Demo 08 where a new type is created TPyPoint and a method 
called
OffsetBy is added by AddMethod.
I am including the following statement in TForm1.Button1Click after DelphiPoint 
is
created.

 ShowMessage(PythonEngine1.PyObjectAsString(DelphiPoint.GetAttr('OffsetBy')));

It works as expected with Python 2.5, 2.6 and 3.1.

Please resubmit if needed.

Original comment by pyscripter on 10 Dec 2009 at 12:30

GoogleCodeExporter commented 9 years ago
IMPORTANT

I forgot to say that your PythonType needs to have in the TypeFlags the 
tpfBaseType
set.  In the next version it will be set by default.

Original comment by pyscripter on 11 Dec 2009 at 12:45