freelanceprogrammers.org Forum Index » Delphi
puzzle in Demo31/32
Joined: 17 May 2006
Posts: 32
puzzle in Demo31/32
Hi:
I know WrapDelphi unit is very useful. but I found it`s difficult to
understand comletely the code in Demo31/32. Is there any more information
about WrapDelphi exclude the head of WrapDelphi unit?
for example, in Python code in Demo32 ,I found some variant named
EBadPoint, PointError. but I don`t find them in anywhere. How they are
put into spam module?
Any suggestion to me is appreciate.
--tocer
Joined: 29 Apr 2005
Posts: 103
puzzle in Demo31/32
--- In pythonfordelphi@yahoogroups.com, tocer <tocer.deng@...> wrote:
>
> Hi:
> I know WrapDelphi unit is very useful. but I found it`s
difficult to
> understand comletely the code in Demo31/32. Is there any more
information
> about WrapDelphi exclude the head of WrapDelphi unit?
>
> for example, in Python code in Demo32 ,I found some variant named
> EBadPoint, PointError. but I don`t find them in anywhere. How they
are
> put into spam module?
In this case, this has nothing to do with WrapDelphi. It`s an old
feature that lets you create hierarchies of errors within a module.
See older demos like Demo8 or Demo26.
Select the PythonModule1 component and inspect the Errors property.
Bye,
Morgan
Joined: 17 May 2006
Posts: 32
puzzle in Demo31/32
Hi Morgan:
Thank your reply. I look Demo8 and understand more.
Below is my comprehension about Demo32, I wish someone figure out my
mistake.
I think demo32 impletment two function in fact.
The first is to extend python module using delphi class. You need
declare a normal class and implement it and create instance of it in delphi.
Then you can simply use newest technologe----PyDephiWrapper :) to
wrap the class. such as:
p := PyDelphiWrapper.Wrap(aclass, soOwned);
PythonModule1.SetVar( `myClass`, p );
PythonEngine1.Py_DecRef(p);
then you can from module import myClass in python.
The second is that basing first function, you can inherit in Python
the class created in Delphi. To do it, you have to do more. Such as you
create a delphi normal class named TPoint, then you must create a new
class named TPyPoint(other name is available) who is TPyDelphiPersistent
descendent. in this class, you have to override three method at least:
Create, CreateWith, DelphiObjectClass. Create methed would be call
automately; CreateWith method is used to create a object with parameter
in Python; DelphiObjectClass return the delphi normal class whose name
is import in Python with removing "T" from class name(is my guess right?).
such as "TFoo" in Delphi is converted "Foo" in Python. finally you don`t
forget regist the new class(TPyPoint) using
PyDephiWrapper.RegisterDelphiWrapper.
Now you can use freely the class in Python.
But now, I have two question:
1. could PyDephiWrapper wrap function or procedure not class?
2. is delphi class must inherit from TPersistent? TObject is OK?
thanks again.
--tocer
Morgan Martinet wrote::
> --- In pythonfordelphi@yahoogroups.com, tocer <tocer.deng@...> wrote:
>> Hi:
>> I know WrapDelphi unit is very useful. but I found it`s
> difficult to
>> understand comletely the code in Demo31/32. Is there any more
> information
>> about WrapDelphi exclude the head of WrapDelphi unit?
>>
>> for example, in Python code in Demo32 ,I found some variant named
>> EBadPoint, PointError. but I don`t find them in anywhere. How they
> are
>> put into spam module?
> In this case, this has nothing to do with WrapDelphi. It`s an old
> feature that lets you create hierarchies of errors within a module.
> See older demos like Demo8 or Demo26.
> Select the PythonModule1 component and inspect the Errors property.
>
> Bye,
>
> Morgan
Joined: 29 Apr 2005
Posts: 103
puzzle in Demo31/32
> The first is to extend python module using delphi class. You need
> declare a normal class and implement it and create instance of it in
> delphi.
> Then you can simply use newest technologe----PyDephiWrapper :) to
> wrap the class. such as:
>
> p := PyDelphiWrapper.Wrap(aclass, soOwned);
>
> PythonModule1.SetVar( `myClass`, p );
> PythonEngine1.Py_DecRef(p);
>
> then you can from module import myClass in python.
> The second is that basing first function, you can inherit in Python
> the class created in Delphi. To do it, you have to do more. Such as you
> create a delphi normal class named TPoint, then you must create a new
> class named TPyPoint(other name is available) who is TPyDelphiPersistent
> descendent. in this class, you have to override three method at least:
> Create, CreateWith, DelphiObjectClass. Create methed would be call
> automately; CreateWith method is used to create a object with parameter
> in Python; DelphiObjectClass return the delphi normal class whose name
> is import in Python with removing "T" from class name(is my guess right?).
> such as "TFoo" in Delphi is converted "Foo" in Python. finally you don`t
> forget regist the new class(TPyPoint) using
> PyDephiWrapper.RegisterDelphiWrapper.
> Now you can use freely the class in Python.
Right
>
> But now, I have two question:
>
> 1. could PyDephiWrapper wrap function or procedure not class?
Nope. The wrapper will use RTTI information which can be generated only for
a class, using the Published section or the {$METHODINFO ON} directive.
> 2. is delphi class must inherit from TPersistent? TObject is OK?
It should be ok to inherit from TObject.
Bye,
Morgan
Joined: 17 May 2006
Posts: 32
puzzle in Demo31/32
Hi Morgan:
in Demo32, I move "procedure OffsetBy( dx, dy : integer );" from public
to published section. I run the demo and execute python statement:
import spam
print dir(spam.myPoint)
print spam.myPoint.__published__
I couldn`t find method "OffsetBy" in result. But we can call the method.
It seems that the properties could be exposed in python , but method
not. why?
--tocer
Morgan Martinet wrote::
>>
>> 1. could PyDephiWrapper wrap function or procedure not class?
> Nope. The wrapper will use RTTI information which can be generated only for
> a class, using the Published section or the {$METHODINFO ON} directive.
>
>> 2. is delphi class must inherit from TPersistent? TObject is OK?
> It should be ok to inherit from TObject.
>
> Bye,
>
> Morgan
Joined: 29 Apr 2005
Posts: 103
puzzle in Demo31/32
> in Demo32, I move "procedure OffsetBy( dx, dy : integer );" from
public
> to published section. I run the demo and execute python statement:
>
> import spam
> print dir(spam.myPoint)
> print spam.myPoint.__published__
>
> I couldn`t find method "OffsetBy" in result. But we can call the
method.
> It seems that the properties could be exposed in python , but
method
> not. why?
__publised__ will use the RTTI GetPropList function but it will
return only the published properties. WrapDelphi uses GetMethodInfo
in the module ObjAuto to find a method, but this module doesn`t
expose a function that returns the list of methods for a type, so
I`ll have to copy the GetMethodInfo code in order to build the list
of available methods...
Morgan
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
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.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







