[XE2] Access violation at TDataModule's constructor - SOLVED

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

[XE2] Access violation at TDataModule's constructor - SOLVED

Postby macicogna » Mon May 09, 2016 8:11 am

Hi All,

I've been working in the migration of two projects (A and B for reference) from RAD 2009 to CXE2 and in one of them I had a problem with the constructor of a TDataModule unit at runtime.

Project A uses this TMyDMod class withou any compilation and runtime problem.

Project B also uses TMyDMod but I receive a error message when it reaches the constructor, at runtime:

Code: Select all
__fastcall TMyDMod::TMyDMod(TComponent* Owner)
: TDataModule(Owner)  //<-- Here
{...
}


The error message is:

Code: Select all
Project MyPrj.exe raised exception class $C0000005 with message 'access violation at 0x500439e1: read of address 0xf29efd03'.


Here is the Call Stack if I Break the runtime at the error message, using the debugger.

Call Stack
Code: Select all
rtl160.@System@Classes@UTF8ToUnicodeString...
rtl160.@System@Classes@UTF8ToString...
rtl160.@System@Classes@TReader@GetFieldClass...


I think it might be related with some Project option for Unicode and/or reading the DFM file, but I couldn't find a reason. Besides, it could be something related with the ZeosLib framework configuration in Projec B, but I've checked twice with Project A and haven't found any difference. At design time TMyDMod opens without any problem

Also, I've created a new Project B from scratch in CXE2, but the same problem raised again.

O hope someone can help.

Thanks,

Marcelo.
Last edited by macicogna on Tue May 10, 2016 9:36 am, edited 1 time in total.
User avatar
macicogna
BCBJ Veteran
BCBJ Veteran
 
Posts: 63
Joined: Mon Aug 04, 2008 4:57 pm
Location: Brazil

Re: [XE2] Access violation at TDataModule's constructor

Postby minas » Mon May 09, 2016 2:57 pm

just a thought ...
is DataModule in AutoCreated Forms in Project B (Project->Options->Forms) ?
-
User avatar
minas
BCBJ Guru
BCBJ Guru
 
Posts: 196
Joined: Sat Jul 10, 2004 6:09 am
Location: Greece

Re: [XE2] Access violation at TDataModule's constructor

Postby macicogna » Mon May 09, 2016 3:36 pm

Yes, but it is in Project A and B.

Thanks.
User avatar
macicogna
BCBJ Veteran
BCBJ Veteran
 
Posts: 63
Joined: Mon Aug 04, 2008 4:57 pm
Location: Brazil

Re: [XE2] Access violation at TDataModule's constructor - SO

Postby macicogna » Tue May 10, 2016 10:20 am

Hi All,

Damon, If BCBJ needs an article about Project Migration, now I have a good one.
(just kidding...)


I've found the cause of my problem and I think I can share it with you in order to help others in the future, mainly with practices about how to update or migrate project to new versions of the IDE.

Actually, Project A was wrong. Say what? Yes, the project that was compiling and running was wrong. Here is the an abstract of my journey:

Scenario
  1. After the project conversion, I've edited the .CBPROJ file outside the CXE2 IDE removing references used in RAD 2009. For example, I've removed Tee*8*, QR*C2009 and TMS*2009* references. In particular, I've removed ZeosLib's Z*120, Z*120.lib and Z*120.bpi references.
  2. In the IDE, I should have gone to "Project > Options > Packages" and unchecked and checked (again) my third party components, now installed with new versions compatible with CXE2. So, now I estimate that I might forgot to unchecked and checked the "Zeos Database Components" package in Project A.
  3. When compiling Project A, as ZeosLib's Include and Library paths were OK, the linker complained about not found "ZAbstractConnection.obj", due to automatic #pragma link entries. And here was my second mistake, I've recompiled ZeosLib packages without deleting .obj files, what I used to do before testing Project A an B with CXE2.
  4. With this change, Project A compiled and ran OK. Doing that, now I estimate that the executable was not dynamic linked to ZeosLib's BPL files. In other words, Project A was statically linked to ZeosLib's .OBJ files and forgot about the Z*160.LIB files.
  5. With Project B I've unchecked and checked the "Zeos Database Components" package, so the executable was linked with ZeosLib's BPL files. I think something was wrong among .LIB and .OBJ files. It compiled, but raised the access violation that started this thread.
  6. I've discover the problem when I unchecked the "Link with runtime packages" rebuild Project B and it ran OK. To prove this, I've tested Project A with checked "Link with runtime packages" and notice that no Z*.bpl files were shown in the Modules view (Ctrl+Alt+M) option.

Solution
  1. First, I've recompiled ZeosLib's packages, deleting .OBJ and just keeping .LIB and .BPI files.
  2. In Project A, I've unchecked and checked the "Zeos Database Components" package, so the Z*160, Z*160.lib and Z*160.bpi references were rebuilt in the CXE2's .CBPROJ file.
  3. Rebuild Project A and Project B and now are running OK.

As a new understanding, now I've changed my manuals to Update, and not Delete, the third party component references after the IDE migration. If I delete the old references, "please remember" to uncheck and check them again to recompose new references.

That's it.

I hope I can help other C++Builder's knights.

Best,

Marcelo.
Last edited by macicogna on Wed May 11, 2016 6:47 am, edited 1 time in total.
User avatar
macicogna
BCBJ Veteran
BCBJ Veteran
 
Posts: 63
Joined: Mon Aug 04, 2008 4:57 pm
Location: Brazil

Re: [XE2] Access violation at TDataModule's constructor - SO

Postby 2ffat » Wed May 11, 2016 5:43 am

Thank you.
James P. Cottingham

Look at me still talking
when there is science to do.
User avatar
2ffat
Forum Mod
Forum Mod
 
Posts: 427
Joined: Wed Jun 23, 2004 7:07 am
Location: South Hill, VA


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 7 guests

cron