freelanceprogrammers.org Forum Index » Delphi

Why am I getting null python object in Delphi?

View user's profile Post To page top
ice.tortoise Posted: Mon Oct 23, 2006 8:57 pm


Joined: 15 Aug 2006

Posts: 7
Why am I getting null python object in Delphi?
Hi guys,

I have met a problem with my little program using PY4D. I
wrapped(using WrapDelphi) a class called UIController in delphi so
that my py scripts can use to update UI.

Everything is fine when py scripts call the controller with strings,
the controller displays just fine. The problem happens when py scripts
try to call the controller with a customized py class, in my case, it
is a "Task" class holding many information(task description, execute
time, etc.) However, instead of my Task object, i get only null.

The py code looks like this:
class Task:
def execution(self):
"""Display the message in delphi program."""
controller.PopReminder(self)#controller is an instance of the
wrapped class.

The controller class:
procedure TUIController.PopReminder( pyTaskPointer : Variant );

And the problem is the "pyTaskPointer" is always null while the same
code works with the type of String.

What did I miss here?

Thanks,

Andy
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Tue Oct 24, 2006 7:23 am


Joined: 29 Apr 2005

Posts: 103
Why am I getting null python object in Delphi?
Hi,

I`m sorry but the current implementation does not allow this. I
guess this could be easily implemented and I`ll have a look as soon
as I can.
For now, you`ll have to either code your Python/Delphi class the
Demo8 way or you can try to mix old way and wrapped style by looking
at Demo32.
If you create a TPyUIController like the TPyPoint that wraps your
TUIController class, then you can override the RegisterMethods and
provide a PopReminder_Wrapper that will parse the method arguments
then call your PopReminder wrapper.
You can open the WrapDelphiClasses unit and inspect the
TPyDelphiPersistent class, and the Assign_Wrapper method that takes
a single object as argument.
The wrapper method uses the PyArg_ParseTuple api to crunch the
parameters.
Note that you don`t need to call the CheckObjAttribute helper
function like in Assign() because this function expects a wrapped
delphi object and in your case you would receive a regular Python
class.
So, I would simply use VarPyth and do something like:

function TPyUIController.PopReminder_Wrapper(args: PPyObject):
PPyObject;
var
_obj : PPyObject;
_task : Variant;
begin
with GetPythonEngine do
begin
// We adjust the transmitted self argument
Adjust(@Self);
if PyArg_ParseTuple( args, `O:PopReminder`, [@_obj] ) <> 0 then
begin
_task := VarPythonCreate(_obj);
DelphiObject.PopReminder(_task.execute_time,
_task.description); // or pass the variant as parameter...
Result := ReturnNone; // or anything else...
end
else
Result := nil;
end;
end;

class procedure TPyUIController.RegisterMethods(
PythonType: TPythonType);
begin
inherited;
PythonType.AddMethod(PopReminder`,
@TPyUIController.PopReminder_Wrapper,
TUIController.PopReminder(task)`#10 +
`...`);
end;

class function TPyUIController.DelphiObjectClass: TClass;
begin
Result := TUIController;
end;


Hope this helps,

Morgan

--- In pythonfordelphi@yahoogroups.com, "ice.tortoise"
<ice.tortoise@...> wrote:
>
> Hi guys,
>
> I have met a problem with my little program using PY4D. I
> wrapped(using WrapDelphi) a class called UIController in delphi so
> that my py scripts can use to update UI.
>
> Everything is fine when py scripts call the controller with
strings,
> the controller displays just fine. The problem happens when py
scripts
> try to call the controller with a customized py class, in my case,
it
> is a "Task" class holding many information(task description,
execute
> time, etc.) However, instead of my Task object, i get only null.
>
> The py code looks like this:
> class Task:
> def execution(self):
> """Display the message in delphi program."""
> controller.PopReminder(self)#controller is an instance of
the
> wrapped class.
>
> The controller class:
> procedure TUIController.PopReminder( pyTaskPointer : Variant );
>
> And the problem is the "pyTaskPointer" is always null while the
same
> code works with the type of String.
>
> What did I miss here?
>
> Thanks,
>
> Andy
>
Reply with quote
Send private message
View user's profile Post To page top
ice.tortoise Posted: Tue Oct 24, 2006 9:07 pm


Joined: 15 Aug 2006

Posts: 7
Why am I getting null python object in Delphi?
The compiler is complaining that there`s no PopReminder on
DelphiObject object at the code:
DelphiObject.PopReminder(_task.execute_time,
> _task.description); // or pass the variant as parameter...

Any workaround on this one?

Thanks for the reply:-)

--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@...>
wrote:
>
> Hi,
>
> I`m sorry but the current implementation does not allow this. I
> guess this could be easily implemented and I`ll have a look as soon
> as I can.
> For now, you`ll have to either code your Python/Delphi class the
> Demo8 way or you can try to mix old way and wrapped style by looking
> at Demo32.
> If you create a TPyUIController like the TPyPoint that wraps your
> TUIController class, then you can override the RegisterMethods and
> provide a PopReminder_Wrapper that will parse the method arguments
> then call your PopReminder wrapper.
> You can open the WrapDelphiClasses unit and inspect the
> TPyDelphiPersistent class, and the Assign_Wrapper method that takes
> a single object as argument.
> The wrapper method uses the PyArg_ParseTuple api to crunch the
> parameters.
> Note that you don`t need to call the CheckObjAttribute helper
> function like in Assign() because this function expects a wrapped
> delphi object and in your case you would receive a regular Python
> class.
> So, I would simply use VarPyth and do something like:
>
> function TPyUIController.PopReminder_Wrapper(args: PPyObject):
> PPyObject;
> var
> _obj : PPyObject;
> _task : Variant;
> begin
> with GetPythonEngine do
> begin
> // We adjust the transmitted self argument
> Adjust(@Self);
> if PyArg_ParseTuple( args, `O:PopReminder`, [@_obj] ) <> 0 then
> begin
> _task := VarPythonCreate(_obj);
> DelphiObject.PopReminder(_task.execute_time,
> _task.description); // or pass the variant as parameter...
> Result := ReturnNone; // or anything else...
> end
> else
> Result := nil;
> end;
> end;
>
> class procedure TPyUIController.RegisterMethods(
> PythonType: TPythonType);
> begin
> inherited;
> PythonType.AddMethod(PopReminder`,
> @TPyUIController.PopReminder_Wrapper,
> TUIController.PopReminder(task)`#10 +
> `...`);
> end;
>
> class function TPyUIController.DelphiObjectClass: TClass;
> begin
> Result := TUIController;
> end;
>
>
> Hope this helps,
>
> Morgan
>
> --- In pythonfordelphi@yahoogroups.com, "ice.tortoise"
> <ice.tortoise@> wrote:
> >
> > Hi guys,
> >
> > I have met a problem with my little program using PY4D. I
> > wrapped(using WrapDelphi) a class called UIController in delphi so
> > that my py scripts can use to update UI.
> >
> > Everything is fine when py scripts call the controller with
> strings,
> > the controller displays just fine. The problem happens when py
> scripts
> > try to call the controller with a customized py class, in my case,
> it
> > is a "Task" class holding many information(task description,
> execute
> > time, etc.) However, instead of my Task object, i get only null.
> >
> > The py code looks like this:
> > class Task:
> > def execution(self):
> > """Display the message in delphi program."""
> > controller.PopReminder(self)#controller is an instance of
> the
> > wrapped class.
> >
> > The controller class:
> > procedure TUIController.PopReminder( pyTaskPointer : Variant );
> >
> > And the problem is the "pyTaskPointer" is always null while the
> same
> > code works with the type of String.
> >
> > What did I miss here?
> >
> > Thanks,
> >
> > Andy
> >
>
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Thu Oct 26, 2006 6:53 am


Joined: 29 Apr 2005

Posts: 103
Why am I getting null python object in Delphi?
--- In pythonfordelphi@yahoogroups.com, "ice.tortoise"
<ice.tortoise@...> wrote:
>
> The compiler is complaining that there`s no PopReminder on
> DelphiObject object at the code:
> DelphiObject.PopReminder(_task.execute_time,
> > _task.description); // or pass the variant as parameter...
>
> Any workaround on this one?
If the compiler says that, it means that you didn`t redeclare
DelphiObject using your TUIController class!!!!
Look at TPyDelphiPersistent and see how it redeclares the property
with the TPersistent type...

>
> Thanks for the reply:-)
>
> --- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@>
> wrote:
> >
> > Hi,
> >
> > I`m sorry but the current implementation does not allow this. I
> > guess this could be easily implemented and I`ll have a look as
soon
> > as I can.
> > For now, you`ll have to either code your Python/Delphi class the
> > Demo8 way or you can try to mix old way and wrapped style by
looking
> > at Demo32.
> > If you create a TPyUIController like the TPyPoint that wraps
your
> > TUIController class, then you can override the RegisterMethods
and
> > provide a PopReminder_Wrapper that will parse the method
arguments
> > then call your PopReminder wrapper.
> > You can open the WrapDelphiClasses unit and inspect the
> > TPyDelphiPersistent class, and the Assign_Wrapper method that
takes
> > a single object as argument.
> > The wrapper method uses the PyArg_ParseTuple api to crunch the
> > parameters.
> > Note that you don`t need to call the CheckObjAttribute helper
> > function like in Assign() because this function expects a
wrapped
> > delphi object and in your case you would receive a regular
Python
> > class.
> > So, I would simply use VarPyth and do something like:
> >
> > function TPyUIController.PopReminder_Wrapper(args: PPyObject):
> > PPyObject;
> > var
> > _obj : PPyObject;
> > _task : Variant;
> > begin
> > with GetPythonEngine do
> > begin
> > // We adjust the transmitted self argument
> > Adjust(@Self);
> > if PyArg_ParseTuple( args, `O:PopReminder`, [@_obj] ) <> 0
then
> > begin
> > _task := VarPythonCreate(_obj);
> > DelphiObject.PopReminder(_task.execute_time,
> > _task.description); // or pass the variant as parameter...
> > Result := ReturnNone; // or anything else...
> > end
> > else
> > Result := nil;
> > end;
> > end;
> >
> > class procedure TPyUIController.RegisterMethods(
> > PythonType: TPythonType);
> > begin
> > inherited;
> > PythonType.AddMethod(PopReminder`,
> > @TPyUIController.PopReminder_Wrapper,
> > TUIController.PopReminder(task)`#10 +
> > `...`);
> > end;
> >
> > class function TPyUIController.DelphiObjectClass: TClass;
> > begin
> > Result := TUIController;
> > end;
> >
> >
> > Hope this helps,
> >
> > Morgan
> >
> > --- In pythonfordelphi@yahoogroups.com, "ice.tortoise"
> > <ice.tortoise@> wrote:
> > >
> > > Hi guys,
> > >
> > > I have met a problem with my little program using PY4D. I
> > > wrapped(using WrapDelphi) a class called UIController in
delphi so
> > > that my py scripts can use to update UI.
> > >
> > > Everything is fine when py scripts call the controller with
> > strings,
> > > the controller displays just fine. The problem happens when py
> > scripts
> > > try to call the controller with a customized py class, in my
case,
> > it
> > > is a "Task" class holding many information(task description,
> > execute
> > > time, etc.) However, instead of my Task object, i get only
null.
> > >
> > > The py code looks like this:
> > > class Task:
> > > def execution(self):
> > > """Display the message in delphi program."""
> > > controller.PopReminder(self)#controller is an instance
of
> > the
> > > wrapped class.
> > >
> > > The controller class:
> > > procedure TUIController.PopReminder( pyTaskPointer : Variant );
> > >
> > > And the problem is the "pyTaskPointer" is always null while
the
> > same
> > > code works with the type of String.
> > >
> > > What did I miss here?
> > >
> > > Thanks,
> > >
> > > Andy
> > >
> >
>
Reply with quote
Send private message
View user's profile Post To page top
ice.tortoise Posted: Sun Oct 29, 2006 9:57 pm


Joined: 15 Aug 2006

Posts: 7
Why am I getting null python object in Delphi?
Got this handled already, thanks anyway...and sorry for not knowing
much about delphi...first time to try it...

--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@...>
wrote:
>
> --- In pythonfordelphi@yahoogroups.com, "ice.tortoise"
> <ice.tortoise@> wrote:
> >
> > The compiler is complaining that there`s no PopReminder on
> > DelphiObject object at the code:
> > DelphiObject.PopReminder(_task.execute_time,
> > > _task.description); // or pass the variant as parameter...
> >
> > Any workaround on this one?
> If the compiler says that, it means that you didn`t redeclare
> DelphiObject using your TUIController class!!!!
> Look at TPyDelphiPersistent and see how it redeclares the property
> with the TPersistent type...
>
> >
> > Thanks for the reply:-)
> >
> > --- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@>
> > wrote:
> > >
> > > Hi,
> > >
> > > I`m sorry but the current implementation does not allow this. I
> > > guess this could be easily implemented and I`ll have a look as
> soon
> > > as I can.
> > > For now, you`ll have to either code your Python/Delphi class the
> > > Demo8 way or you can try to mix old way and wrapped style by
> looking
> > > at Demo32.
> > > If you create a TPyUIController like the TPyPoint that wraps
> your
> > > TUIController class, then you can override the RegisterMethods
> and
> > > provide a PopReminder_Wrapper that will parse the method
> arguments
> > > then call your PopReminder wrapper.
> > > You can open the WrapDelphiClasses unit and inspect the
> > > TPyDelphiPersistent class, and the Assign_Wrapper method that
> takes
> > > a single object as argument.
> > > The wrapper method uses the PyArg_ParseTuple api to crunch the
> > > parameters.
> > > Note that you don`t need to call the CheckObjAttribute helper
> > > function like in Assign() because this function expects a
> wrapped
> > > delphi object and in your case you would receive a regular
> Python
> > > class.
> > > So, I would simply use VarPyth and do something like:
> > >
> > > function TPyUIController.PopReminder_Wrapper(args: PPyObject):
> > > PPyObject;
> > > var
> > > _obj : PPyObject;
> > > _task : Variant;
> > > begin
> > > with GetPythonEngine do
> > > begin
> > > // We adjust the transmitted self argument
> > > Adjust(@Self);
> > > if PyArg_ParseTuple( args, `O:PopReminder`, [@_obj] ) <> 0
> then
> > > begin
> > > _task := VarPythonCreate(_obj);
> > > DelphiObject.PopReminder(_task.execute_time,
> > > _task.description); // or pass the variant as parameter...
> > > Result := ReturnNone; // or anything else...
> > > end
> > > else
> > > Result := nil;
> > > end;
> > > end;
> > >
> > > class procedure TPyUIController.RegisterMethods(
> > > PythonType: TPythonType);
> > > begin
> > > inherited;
> > > PythonType.AddMethod(PopReminder`,
> > > @TPyUIController.PopReminder_Wrapper,
> > > TUIController.PopReminder(task)`#10 +
> > > `...`);
> > > end;
> > >
> > > class function TPyUIController.DelphiObjectClass: TClass;
> > > begin
> > > Result := TUIController;
> > > end;
> > >
> > >
> > > Hope this helps,
> > >
> > > Morgan
> > >
> > > --- In pythonfordelphi@yahoogroups.com, "ice.tortoise"
> > > <ice.tortoise@> wrote:
> > > >
> > > > Hi guys,
> > > >
> > > > I have met a problem with my little program using PY4D. I
> > > > wrapped(using WrapDelphi) a class called UIController in
> delphi so
> > > > that my py scripts can use to update UI.
> > > >
> > > > Everything is fine when py scripts call the controller with
> > > strings,
> > > > the controller displays just fine. The problem happens when py
> > > scripts
> > > > try to call the controller with a customized py class, in my
> case,
> > > it
> > > > is a "Task" class holding many information(task description,
> > > execute
> > > > time, etc.) However, instead of my Task object, i get only
> null.
> > > >
> > > > The py code looks like this:
> > > > class Task:
> > > > def execution(self):
> > > > """Display the message in delphi program."""
> > > > controller.PopReminder(self)#controller is an instance
> of
> > > the
> > > > wrapped class.
> > > >
> > > > The controller class:
> > > > procedure TUIController.PopReminder( pyTaskPointer : Variant );
> > > >
> > > > And the problem is the "pyTaskPointer" is always null while
> the
> > > same
> > > > code works with the type of String.
> > > >
> > > > What did I miss here?
> > > >
> > > > Thanks,
> > > >
> > > > Andy
> > > >
> > >
> >
>
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