freelanceprogrammers.org Forum Index » Delphi

I`m getting EAccessViolation


View user's profile Post To page top
BigDeny Posted: Sun Mar 19, 2006 10:11 pm


Joined: 21 Apr 2006

Posts: 13
I`m getting EAccessViolation
I`m using following code:
wrap is Wrapper other objects are DelphiVar

function TfrmOverdue.buildEmail(overdue: TGroupped): String;
var p1, p2, p3 : PPyObject;
begin
if not initialized then begin
PythonModule1.Engine := GetPythonEngine;
PythonModule1.Initialize;
wrap.Engine := GetPythonEngine;
wrap.Initialize;
template.Engine := GetPythonEngine;
template.Initialize;
tplFileName.Engine := GetPythonEngine;
tplFileName.Initialize;
myName.Engine := GetPythonEngine;
myName.Initialize;
member.Engine := GetPythonEngine;
member.Initialize;
initialized := True;
end;

// info will be owned and eventually destroyed by Python
p1 := wrap.Wrap(overdue.movies, soReference);
PythonModule1.SetVar(`movies`, p1);

p2 := wrap.Wrap(overdue.games, soReference);
PythonModule1.SetVar(`games`, p2);

p3 := wrap.Wrap(overdue.books, soReference);
PythonModule1.SetVar(`books`, p3);

if overdue.movies <> nil then
currMember := overdue.movies.Member.Member
else if overdue.games <> nil then
currMember := overdue.games.Member.Member
else if overdue.books <> nil then
currMember := overdue.books.Member.Member
else
currMember := `xCollect`;

//PythonModule1.SetVar incremented reference count so we need to
decrement it,
// so that the object will be freed when out of scope
GetPythonEngine.Py_DecRef(p1);
GetPythonEngine.Py_DecRef(p2);
GetPythonEngine.Py_DecRef(p3);
GetPythonEngine.ExecString(txtScript.Lines.Text);

//DO I need to do anything of the next 6 lines
//it doesn`t mater exception is there with or without
GetPythonEngine.Py_XDECREF(p1);
GetPythonEngine.Py_XDECREF(p2);
GetPythonEngine.Py_XDECREF(p3);
PythonModule1.DeleteVar(`movies`);
PythonModule1.DeleteVar(`games`);
PythonModule1.DeleteVar(`books`);
end;

python code is:
# -*- coding: UTF-8 -*-
import overdue
from Cheetah.Template import Template, Filters

t = Template(file=overdue.tplFileName.Value, searchList=[{`overdue`:
overdue, `languageCode` : `%s`}])

#get html from template
overdue.templateResult.Value = t.__str__();
#------------------------------------

and the exception:
Exception class: EAccessViolation
Exception address: 00574F97
--------------------------------------------------------------------------------
--------------------
Stack list, generated 19.3.2006 16:58:39
[00574F97] MethodCallBack.MethodCallBack.GetCodeMem (Line 148,
"MethodCallBack.pas" + 20) + $3
[00404AAB] System.System.@HandleAnyException (Line 133,
"FastMM4Messages.pas" + 0) + $3AAB
[0057502F] MethodCallBack.MethodCallBack.GetCallBack (Line 289,
"MethodCallBack.pas" + 12) + $C
[00585827] PythonEngine.PythonEngine.TPythonType.InitServices (Line
8869, "PythonEngine.pas" + 49) + $E
[00585DFD] PythonEngine.PythonEngine.TPythonType.Initialize (Line
9057, "PythonEngine.pas" + 18) + $2
[00829B0D] WrapDelphi.WrapDelphi.TPyDelphiWrapper.Initialize (Line
2930, "WrapDelphi.pas" + 7) + $8
[00849256] fOverdue.fOverdue.TfrmOverdue.buildEmail (Line 126,
"fOverdue.pas" + 5) + $8
[008498A5] fOverdue.fOverdue.TfrmOverdue.cmdSendClick (Line 252,
"fOverdue.pas" + 12) + $13
[00470910] Controls.Controls.TControl.Click + $64
[0044DE66] StdCtrls.StdCtrls.TButton.Click + $1E
[0044DF64] StdCtrls.StdCtrls.TButton.CNCommand + $C
[0047040B] Controls.Controls.TControl.WndProc + $2BB
[00474234] Controls.Controls.TWinControl.WndProc + $46C
[0044DD10] StdCtrls.StdCtrls.TButtonControl.WndProc + $6C
[00470098] Controls.Controls.TControl.Perform + $24
[0047436B] Controls.Controls.DoControlMsg + $23
[00474ADF] Controls.Controls.TWinControl.WMCommand + $B
[00489478] Forms.Forms.TCustomForm.WMCommand + $2C
[0047040B] Controls.Controls.TControl.WndProc + $2BB
[00474317] Controls.Controls.TWinControl.DefaultHandler + $D7
[0047040B] Controls.Controls.TControl.WndProc + $2BB
[00474234] Controls.Controls.TWinControl.WndProc + $46C
[0053CBE8] TB2Hook.TB2Hook.CallWndProcHook (Line 98, "TB2Hook.pas" +
15) + $18
[004869C1] Forms.Forms.TCustomForm.WndProc + $4C1
[004739EC] Controls.Controls.TWinControl.MainWndProc + $2C
[00431BC4] Classes.Classes.StdWndProc + $14
[00474317] Controls.Controls.TWinControl.DefaultHandler + $D7
[00470D30] Controls.Controls.TControl.WMLButtonUp + $10
[0047040B] Controls.Controls.TControl.WndProc + $2BB
[00473D27] Controls.Controls.TWinControl.IsControlMouseMsg + $13
[00474234] Controls.Controls.TWinControl.WndProc + $46C
[0044DD10] StdCtrls.StdCtrls.TButtonControl.WndProc + $6C
[004739EC] Controls.Controls.TWinControl.MainWndProc + $2C
[00431BC4] Classes.Classes.StdWndProc + $14
[0048E238] Forms.Forms.TApplication.ProcessMessage + $FC
[0048E272] Forms.Forms.TApplication.HandleMessage + $A
[0048A83F] Forms.Forms.TCustomForm.ShowModal + $187
[008D8F6D] fMain.fMain.TfrmMain.actMainLoanOverdueExecute (Line 1051,
"fMain.pas" + 0) + $9
[00430F03] Classes.Classes.TBasicAction.Execute + $F
[0047F311] ActnList.ActnList.TContainedAction.Execute + $31
[0047FFD8] ActnList.ActnList.TCustomAction.Execute + $50
[00430DCF] Classes.Classes.TBasicActionLink.Execute + $13
[0052C509] TB2Item.TB2Item.TTBCustomItem.Click (Line 1496,
"TB2Item.pas" + 19) + $7
[0052C40B] TB2Item.TB2Item.TTBCustomItem.ClickWndProc (Line 1449,
"TB2Item.pas" + 27) + $5
[00431BC4] Classes.Classes.StdWndProc + $14
[0048E238] Forms.Forms.TApplication.ProcessMessage + $FC
[0048E272] Forms.Forms.TApplication.HandleMessage + $A
[0048E492] Forms.Forms.TApplication.Run + $96
[008E6667] xCollect.xCollect.Finalization + $724F
--------------------------------------------------------------------------------
--------------------
System : Windows XP Professional, Version: 5.1, Build: A28, "Service
Pack 2"
Processor: AMD, AMD Athlon(tm) 64 Processor 3000+, 1800 MHz MMX
Display : 1280x1024 pixels, 32 bpp
--------------------------------------------------------------------------------
--------------------

Regards,
Miha
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Mon Mar 20, 2006 5:18 am


Joined: 29 Apr 2005

Posts: 103
I`m getting EAccessViolation
Hi Mika,

Your code is not clear enough for me to help you. Please, send me a working
Delphi project demonstrating the problem.
Which version of Delphi are you using?
Are you using FastMM4?
Apparently, it crashes in the new memory allocator introduced in the latest
version 3.31
Send your project to bugs@...

Thanks,

Morgan

> -----Original Message-----
> From: pythonfordelphi@yahoogroups.com
> [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of BigDeny
> Sent: Sunday, March 19, 2006 11:12 AM
> To: pythonfordelphi@yahoogroups.com
> Subject: [pythonfordelphi] I`m getting EAccessViolation
>
> I`m using following code:
> wrap is Wrapper other objects are DelphiVar
>
> function TfrmOverdue.buildEmail(overdue: TGroupped): String;
> var p1, p2, p3 : PPyObject;
> begin
> if not initialized then begin
> PythonModule1.Engine := GetPythonEngine;
> PythonModule1.Initialize;
> wrap.Engine := GetPythonEngine;
> wrap.Initialize;
> template.Engine := GetPythonEngine;
> template.Initialize;
> tplFileName.Engine := GetPythonEngine;
> tplFileName.Initialize;
> myName.Engine := GetPythonEngine;
> myName.Initialize;
> member.Engine := GetPythonEngine;
> member.Initialize;
> initialized := True;
> end;
>
> // info will be owned and eventually destroyed by Python
> p1 := wrap.Wrap(overdue.movies, soReference);
> PythonModule1.SetVar(`movies`, p1);
>
> p2 := wrap.Wrap(overdue.games, soReference);
> PythonModule1.SetVar(`games`, p2);
>
> p3 := wrap.Wrap(overdue.books, soReference);
> PythonModule1.SetVar(`books`, p3);
>
> if overdue.movies <> nil then
> currMember := overdue.movies.Member.Member
> else if overdue.games <> nil then
> currMember := overdue.games.Member.Member
> else if overdue.books <> nil then
> currMember := overdue.books.Member.Member
> else
> currMember := `xCollect`;
>
> //PythonModule1.SetVar incremented reference count so we need to
> decrement it,
> // so that the object will be freed when out of scope
> GetPythonEngine.Py_DecRef(p1);
> GetPythonEngine.Py_DecRef(p2);
> GetPythonEngine.Py_DecRef(p3);
> GetPythonEngine.ExecString(txtScript.Lines.Text);
>
> //DO I need to do anything of the next 6 lines
> //it doesn`t mater exception is there with or without
> GetPythonEngine.Py_XDECREF(p1);
> GetPythonEngine.Py_XDECREF(p2);
> GetPythonEngine.Py_XDECREF(p3);
> PythonModule1.DeleteVar(`movies`);
> PythonModule1.DeleteVar(`games`);
> PythonModule1.DeleteVar(`books`);
> end;
>
> python code is:
> # -*- coding: UTF-8 -*-
> import overdue
> from Cheetah.Template import Template, Filters
>
> t = Template(file=overdue.tplFileName.Value, searchList=[{`overdue`:
> overdue, `languageCode` : `%s`}])
>
> #get html from template
> overdue.templateResult.Value = t.__str__();
> #------------------------------------
>
> and the exception:
> Exception class: EAccessViolation
> Exception address: 00574F97
> --------------------------------------------------------------------------
> --------------------------
> Stack list, generated 19.3.2006 16:58:39
> [00574F97] MethodCallBack.MethodCallBack.GetCodeMem (Line 148,
> "MethodCallBack.pas" + 20) + $3
> [00404AAB] System.System.@HandleAnyException (Line 133,
> "FastMM4Messages.pas" + 0) + $3AAB
> [0057502F] MethodCallBack.MethodCallBack.GetCallBack (Line 289,
> "MethodCallBack.pas" + 12) + $C
> [00585827] PythonEngine.PythonEngine.TPythonType.InitServices (Line
> 8869, "PythonEngine.pas" + 49) + $E
> [00585DFD] PythonEngine.PythonEngine.TPythonType.Initialize (Line
> 9057, "PythonEngine.pas" + 18) + $2
> [00829B0D] WrapDelphi.WrapDelphi.TPyDelphiWrapper.Initialize (Line
> 2930, "WrapDelphi.pas" + 7) + $8
> [00849256] fOverdue.fOverdue.TfrmOverdue.buildEmail (Line 126,
> "fOverdue.pas" + 5) + $8
> [008498A5] fOverdue.fOverdue.TfrmOverdue.cmdSendClick (Line 252,
> "fOverdue.pas" + 12) + $13
> [00470910] Controls.Controls.TControl.Click + $64
> [0044DE66] StdCtrls.StdCtrls.TButton.Click + $1E
> [0044DF64] StdCtrls.StdCtrls.TButton.CNCommand + $C
> [0047040B] Controls.Controls.TControl.WndProc + $2BB
> [00474234] Controls.Controls.TWinControl.WndProc + $46C
> [0044DD10] StdCtrls.StdCtrls.TButtonControl.WndProc + $6C
> [00470098] Controls.Controls.TControl.Perform + $24
> [0047436B] Controls.Controls.DoControlMsg + $23
> [00474ADF] Controls.Controls.TWinControl.WMCommand + $B
> [00489478] Forms.Forms.TCustomForm.WMCommand + $2C
> [0047040B] Controls.Controls.TControl.WndProc + $2BB
> [00474317] Controls.Controls.TWinControl.DefaultHandler + $D7
> [0047040B] Controls.Controls.TControl.WndProc + $2BB
> [00474234] Controls.Controls.TWinControl.WndProc + $46C
> [0053CBE8] TB2Hook.TB2Hook.CallWndProcHook (Line 98, "TB2Hook.pas" +
> 15) + $18
> [004869C1] Forms.Forms.TCustomForm.WndProc + $4C1
> [004739EC] Controls.Controls.TWinControl.MainWndProc + $2C
> [00431BC4] Classes.Classes.StdWndProc + $14
> [00474317] Controls.Controls.TWinControl.DefaultHandler + $D7
> [00470D30] Controls.Controls.TControl.WMLButtonUp + $10
> [0047040B] Controls.Controls.TControl.WndProc + $2BB
> [00473D27] Controls.Controls.TWinControl.IsControlMouseMsg + $13
> [00474234] Controls.Controls.TWinControl.WndProc + $46C
> [0044DD10] StdCtrls.StdCtrls.TButtonControl.WndProc + $6C
> [004739EC] Controls.Controls.TWinControl.MainWndProc + $2C
> [00431BC4] Classes.Classes.StdWndProc + $14
> [0048E238] Forms.Forms.TApplication.ProcessMessage + $FC
> [0048E272] Forms.Forms.TApplication.HandleMessage + $A
> [0048A83F] Forms.Forms.TCustomForm.ShowModal + $187
> [008D8F6D] fMain.fMain.TfrmMain.actMainLoanOverdueExecute (Line 1051,
> "fMain.pas" + 0) + $9
> [00430F03] Classes.Classes.TBasicAction.Execute + $F
> [0047F311] ActnList.ActnList.TContainedAction.Execute + $31
> [0047FFD8] ActnList.ActnList.TCustomAction.Execute + $50
> [00430DCF] Classes.Classes.TBasicActionLink.Execute + $13
> [0052C509] TB2Item.TB2Item.TTBCustomItem.Click (Line 1496,
> "TB2Item.pas" + 19) + $7
> [0052C40B] TB2Item.TB2Item.TTBCustomItem.ClickWndProc (Line 1449,
> "TB2Item.pas" + 27) + $5
> [00431BC4] Classes.Classes.StdWndProc + $14
> [0048E238] Forms.Forms.TApplication.ProcessMessage + $FC
> [0048E272] Forms.Forms.TApplication.HandleMessage + $A
> [0048E492] Forms.Forms.TApplication.Run + $96
> [008E6667] xCollect.xCollect.Finalization + $724F
> --------------------------------------------------------------------------
> --------------------------
> System : Windows XP Professional, Version: 5.1, Build: A28, "Service
> Pack 2"
> Processor: AMD, AMD Athlon(tm) 64 Processor 3000+, 1800 MHz MMX
> Display : 1280x1024 pixels, 32 bpp
> --------------------------------------------------------------------------
> --------------------------
>
> Regards,
> Miha
>
>
>
>
>
>
>
>
> To Post a message, send it to: pythonfordelphi@eGroups.com
>
> To Unsubscribe, send a blank message to: pythonfordelphi-
> unsubscribe@eGroups.com
> Yahoo! Groups Links
>
>
>
>
Reply with quote
Send private message
View user's profile Post To page top
BigDeny Posted: Mon Mar 20, 2006 2:30 pm


Joined: 21 Apr 2006

Posts: 13
I`m getting EAccessViolation
--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@...>
wrote:
>
> Hi Mika,
Miha :)

> Your code is not clear enough for me to help you. Please, send me a
working
> Delphi project demonstrating the problem.
I`ll give you full sources it`s opensource :)
> Which version of Delphi are you using?
BDS 2006
> Are you using FastMM4?
Yes.
> Apparently, it crashes in the new memory allocator introduced in the
latest
> version 3.31
> Send your project to bugs@...

I`m using a lot of similar code in this project, but this is the only
one that crashes.

Yahoo groups are truncating domain part of e-mail, could you write
just domain part of e-mail.
Expect DL URL after 16:00 CET

Regards,
Miha
Reply with quote
Send private message
View user's profile Post To page top
BigDeny Posted: Sun Apr 23, 2006 1:13 am


Joined: 21 Apr 2006

Posts: 13
I`m getting EAccessViolation
I had some time and was playing around with code a bit.access violation is gone if I remove all events or one of the events in module.2nd thing is. Similar exception occurs if you inherit form with pythonmodule component on it.e.g. dfm text  inline frmHistroy: TfrmHistroy    Left = 435    Top = 384    Width = 539    Height = 348    TabOrder = 2    TabStop = True    Visible = False    ExplicitLeft = 435    ExplicitTop = 384    inherited PythonModule1: TPythonModule      Events = <        item          Name = `translate`        end        item          Name = `urlEncodePath`        end        item          Name = `dateAsString`        end>    end  endto get rid of exception just need to delete       Events = <        item          Name = `translate`        end        item          Name = `urlEncodePath`        end        item          Name = `dateAsString`        end>Delphi will re-create it but suddenly everything will start working.Regards,Miha
Reply with quote
Send private message
View user's profile Post To page top
BigDeny Posted: Mon May 15, 2006 11:20 pm


Joined: 21 Apr 2006

Posts: 13
I`m getting EAccessViolation
Ok. Some more issues. The problem is that all events, objects,
variables, you warp to python get registered under all modules.

I was wrapping 3 functions (with same name) in 4 diffrent modules and
they somewhat get overwrittten badly or sth like that. I created new
module where I register all of them just once and everything works.
It`s a partial workaround. It would still be nice if this would be
resolved.

Now a couple of other things:
- why are all "objects" you wrap "wrapped" to all modules
- another annoying thing is. I put most of my variables I register
most of variables using soReference constant.
and imeddiately I don`t use it anymore I remove variable with
DeleteVar statement and then FreeAndNil delphi object. But damn python
sometimes calls UnSubscribeToFreeNotification, because delphi object
was alredy destroyed of course you get EAccesViolation

even rewriting UnSubscribeToFreeNotification to

procedure TPyDelphiObject.UnSubscribeToFreeNotification;
var
_FreeNotification : IFreeNotification;
begin
Assert(Assigned(fDelphiObject));
try
if fDelphiObject.GetInterface(IFreeNotification, _FreeNotification) then
_FreeNotification.UnSubscribe(Self);
except
//let`s eat it, we get acces violation here, because delphi variable
//doesn`t exist anymore, but python GC tried to I dunno
end;
end;

doesn`t help much because something still get`s fuc*ed up behind the
scenes.

So is there any way to really remove object we registred form python
before we destroy it in code (because DeleteVar method realy doesn`t
help, neither does calling GetPythonEngine.Py_DecRef(p) until ref_cnt
is 0)?

Regards,
Miha
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Tue May 16, 2006 7:32 am


Joined: 29 Apr 2005

Posts: 103
I`m getting EAccessViolation
> Ok. Some more issues. The problem is that all events, objects,
> variables, you warp to python get registered under all modules.
>
> I was wrapping 3 functions (with same name) in 4 diffrent modules and
> they somewhat get overwrittten badly or sth like that. I created new
> module where I register all of them just once and everything works.
> It`s a partial workaround. It would still be nice if this would be
> resolved.
This was to make it simpler when importing the wrappers. One solution is to
name your global functions with unique names, for instance by prefixing the
function name with the module name.
However, from the beginning I figured out that this could become an issue
and that`s why you must provide the unit name when you register your
wrappers:
function TControlsRegistration.Name: String;
begin
Result := `Controls`;
end;

That way, this would be fairly easy to create a new Python module for each
TRegisteredUnit instance.

> Now a couple of other things:
> - why are all "objects" you wrap "wrapped" to all modules
I don`t understand.

> - another annoying thing is. I put most of my variables I register
> most of variables using soReference constant.
> and imeddiately I don`t use it anymore I remove variable with
> DeleteVar statement and then FreeAndNil delphi object. But damn python
> sometimes calls UnSubscribeToFreeNotification, because delphi object
> was alredy destroyed of course you get EAccesViolation
>
> even rewriting UnSubscribeToFreeNotification to
>
> procedure TPyDelphiObject.UnSubscribeToFreeNotification;
> var
> _FreeNotification : IFreeNotification;
> begin
> Assert(Assigned(fDelphiObject));
> try
> if fDelphiObject.GetInterface(IFreeNotification, _FreeNotification) then
> _FreeNotification.UnSubscribe(Self);
> except
> //let`s eat it, we get acces violation here, because delphi variable
> //doesn`t exist anymore, but python GC tried to I dunno
> end;
> end;
>
> doesn`t help much because something still get`s fuc*ed up behind the
> scenes.
>
> So is there any way to really remove object we registred form python
> before we destroy it in code (because DeleteVar method realy doesn`t
> help, neither does calling GetPythonEngine.Py_DecRef(p) until ref_cnt
> is 0)?
Never try to PyDecRef like that as you never know how many references Python
can hold on your object and it will crash in the Python finalization or
anywhere else.

From which class do inherit your wrapped classes?
If they don`t inherit from TComponent then you MUST implement
IFreeNotification instead of trying to swallow the exception!
There is a helper class for this named TFreeNotificationImpl.
Here`s how to do it:

TMyClass = class(TMyParentClass, IFreeNotification, {$IFDEF
DELPHI6_OR_HIGHER}IInterface{$ELSE}IUnknown{$ENDIF})
private
fFreeNotifImpl : TFreeNotificationImpl;
// implementation of interface IUnknown
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
protected
property FreeNotifImpl : TFreeNotificationImpl read fFreeNotifImpl
implements IFreeNotification;
public
constructor Create;
destructor Destroy; override;
end;

constructor TMyClass.Create;
begin
fFreeNotifImpl := TFreeNotificationImpl.Create(Self);
end;

destructor TMyClass.Destroy;
begin
fFreeNotifImpl.Free;
inherited;
end;

function TMyClass._AddRef: Integer;
begin
Result := -1; // we don`t want reference counting
end;

function TMyClass._Release: Integer;
begin
Result := -1; // we don`t want reference counting
end;

function TMyClass.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
if GetInterface(IID, Obj) then
Result := 0
else
Result := E_NOINTERFACE;
end;


This is very important that the wrapper received the notification of the
destruction of the wrapper object or it won`t be able to clear its
reference.

This other alternative is to let the wrapper own the reference on your
object but of course this can lead to other problems.


Bye,

Morgan
Reply with quote
Send private message
View user's profile Post To page top
BigDeny Posted: Tue May 16, 2006 11:49 am


Joined: 21 Apr 2006

Posts: 13
I`m getting EAccessViolation
> One solution is to
> name your global functions with unique names, for instance by
prefixing the
> function name with the module name.
It`s not an option I need to create as simple as possible interface
from delphi to python.

> However, from the beginning I figured out that this could become an
issue
> and that`s why you must provide the unit name when you register your
> wrappers:
> function TControlsRegistration.Name: String;
> begin
> Result := `Controls`;
> end;
I`m providing a name.

> Never try to PyDecRef like that as you never know how many
references Python
> can hold on your object and it will crash in the Python finalization or
> anywhere else.
>
> From which class do inherit your wrapped classes?
> If they don`t inherit from TComponent then you MUST implement
> IFreeNotification instead of trying to swallow the exception!
> There is a helper class for this named TFreeNotificationImpl.
I`m inheriting wrappers from TPyDelphiPersistent, because all classes
are either tcollection, tcollectionitem or tpersistent.

P.S. Because project i`m using p4d is open source you can get sources
an compiled app. at http://sourceforge.net/projects/xcollect. So
getting things right it would make xCollect a great learning point for
newcomers.

Regards,
Miha
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Tue May 16, 2006 7:30 pm


Joined: 29 Apr 2005

Posts: 103
I`m getting EAccessViolation
> > However, from the beginning I figured out that this could become an
> issue
> > and that`s why you must provide the unit name when you register your
> > wrappers:
> > function TControlsRegistration.Name: String;
> > begin
> > Result := `Controls`;
> > end;
> I`m providing a name.
I don`t use it presently anyway...

> > From which class do inherit your wrapped classes?
> > If they don`t inherit from TComponent then you MUST implement
> > IFreeNotification instead of trying to swallow the exception!
> > There is a helper class for this named TFreeNotificationImpl.
> I`m inheriting wrappers from TPyDelphiPersistent, because all classes
> are either tcollection, tcollectionitem or tpersistent.
Inheriting wrappers won`t solve the problem. The wrapped instance must
somehow either notify the wrapper of its destruction or never die!
If you can`t subclass the wrapped instance, then you must keep alive your
referenced instances until Python is finalized.

Anyway, it`s not because you`re inheriting from TPersitent or
TCollectionItem or TCollection that you can`t implement
IFreeNotification!!!!

TMyCollection = class(TCollection, IFreeNotification)...
TMyCollectionItem = class(TCollectionItem, IFreeNotification)...
Collection := TMyCollection.Create(TMyCollectionItem);

Or the alternate solution is that you let the wrapper own your collection,
and you`re the one who keeps a reference on it. Either by using a direct
pointer on your instance, or better by keeping an incremented reference on
the Python wrapper which will guarantee that Python will never destroy your
instance.


Bye,

Morgan
Reply with quote
Send private message
View user's profile Post To page top
BigDeny Posted: Tue May 16, 2006 8:41 pm


Joined: 21 Apr 2006

Posts: 13
I`m getting EAccessViolation
--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@...>
wrote:
> Anyway, it`s not because you`re inheriting from TPersitent or
> TCollectionItem or TCollection that you can`t implement
> IFreeNotification!!!!
>
> TMyCollection = class(TCollection, IFreeNotification)...
> TMyCollectionItem = class(TCollectionItem, IFreeNotification)...
> Collection := TMyCollection.Create(TMyCollectionItem);
>
> Or the alternate solution is that you let the wrapper own your
collection,
> and you`re the one who keeps a reference on it. Either by using a direct
> pointer on your instance, or better by keeping an incremented
reference on
> the Python wrapper which will guarantee that Python will never
destroy your
> instance.

Ok I`ll fix all 40 or so classes. I tought that I don`t need to
implement the IFreeNotification if I`m using TCollection,
TCollectionItem or TPersisten classes. Thanks for help. I really hope
that EAcessviolation errors will stop after I`ll implement
IFreeNotification

Regards,
Miha
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Tue May 16, 2006 8:51 pm


Joined: 29 Apr 2005

Posts: 103
I`m getting EAccessViolation
> Ok I`ll fix all 40 or so classes. I tought that I don`t need to
> implement the IFreeNotification if I`m using TCollection,
> TCollectionItem or TPersisten classes. Thanks for help. I really hope
> that EAcessviolation errors will stop after I`ll implement
> IFreeNotification
Try one class first! ;-)
In fact, create a base collection/base collectionItem that implements
that and then you`re done!

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