BKor 0 Posted November 6 Hello everybody, I installed Rad Studio Athens ( with some graphic 3rd parties) and now I am trying to open some projects that I have done in Alexandria ( Rad Studio11). Unfortunatelly I am not succesfull - (access violation at address 00876830 in module "Project1.exe" (offset 6830). Read of address 000000000.) I am working with C++ Builder and before I had no problems with migrating projects from previous versions of Rad Studio. Any advice that could help me running older projects? Share this post Link to post
shineworld 73 Posted November 6 Try to check the stack of called methods, someone try to use a wrong pointer value or object reference. Share this post Link to post
DelphiUdIT 178 Posted November 6 2 hours ago, BKor said: Any advice that could help me running older projects? You can run with debugger and see what's the cause ... Share this post Link to post
BKor 0 Posted November 7 I am not used to work with debugger or stack of called methods. I will try it anyway. Is it of any help if ( in case of not able to interpret debugger window...) I make a screenshot of debugger window and post it? Share this post Link to post
DelphiUdIT 178 Posted November 7 16 minutes ago, BKor said: I am not used to work with debugger or stack of called methods. I will try it anyway. Is it of any help if ( in case of not able to interpret debugger window...) I make a screenshot of debugger window and post it? If you post here the piece of source code interested and the screen shoot, sure someone can help you. Share this post Link to post
BKor 0 Posted November 8 I tried with debugging, it looks like there is problem with for loop: for (int j=0; j<c; j++) The initial value of j after running with debugging is 12 (j=12, see the image) , although it should start the loop with value j=0. There seems to be another problem with c, which shows no value at all. j and c are defined as follows: TForm1 *Form1; const int c=9; TBitmapLayer* pLayer[c]; int i,j=0; int r; bool slip[c]={ false }; bool bing[c]={ false }; bool bong[c]={ false }; int alpha[c]={ 0 }; ..... If I replace in the loop c with cc ( which is defined solely as int (int cc=9 ; ), not as const int (const int c=9;), then the value of cc shows as expected, that is 9. I might be totally wrong, never worked with a debugger before. I attached the image of debugging window below. Is it possible that some kind of "compile settings", which are different from previous version of RAD Studio make this problem? Thanks for any advice. Share this post Link to post
Anders Melander 1795 Posted November 8 18 minutes ago, BKor said: for (int j=0; j<c; j++) The initial value of j after running with debugging is 12 (j=12, see the image) , although it should start the loop with value j=0. You are inspecting the value of j too early; It hasn't been assigned a value yet. The debugger stops on the breakpoint at the location just before code is executed. Not after the code has been executed. If you step one line into the loop then j will have been assigned the initial value. Share this post Link to post
BKor 0 Posted November 9 I tried to migrate to Rad Studio 12 Athens another older project from Rad Studio 11. I run it with debugger and it shows: 1) still within c++ builder window: 2) then continues to pop up c++ builder window with: 3) After I close all pop up windows it shows in application window another series of alerts: Access violation remains in first case in module rtl290.bpl and then in module Project1.exe I could not monitor anything with debugger, because closing the alerts led me to the application with another series of alerts.... Hmmm, thx for any advice Share this post Link to post
BKor 0 Posted November 9 I am sending the CPU window after debugging pointing to ntdll.dll Share this post Link to post
BKor 0 Posted November 19 On 11/8/2024 at 11:19 PM, Anders Melander said: You are inspecting the value of j too early; It hasn't been assigned a value yet. The debugger stops on the breakpoint at the location just before code is executed. Not after the code has been executed. If you step one line into the loop then j will have been assigned the initial value. If I press Shift F7 (trace to next source line) it throws me to the end of "void __fastcall TForm1::FormCreate(TObject *Sender)" and the j stays unchanged. This happens even If I place breakpoints in the code. Thx for any advice. Share this post Link to post
Anders Melander 1795 Posted November 19 I would just use F8 (Step over) but it shouldn't make a difference. Where do you assign a value to c and where is pLayer (which I assume is a dynamic array) initialized? I think you need to show us some more code so we can make sense of what you are doing - and please use the code block. Share this post Link to post
BKor 0 Posted November 20 22 hours ago, Anders Melander said: I would just use F8 (Step over) but it shouldn't make a difference. Where do you assign a value to c and where is pLayer (which I assume is a dynamic array) initialized? I think you need to show us some more code so we can make sense of what you are doing - and please use the code block. This morning I tried to send the code (via code block) and was refused to submit as potential spam.... I will try to send you this message and afterwards another one with code. In case I will not be allowed to send the code via code block - is there any other way for sending the code? I am sending the header and upper part of the code. I hope it helps somehow. pLayer is part of TImage32 ( graphics32 , 3rd party), defined as array, and c is defined as const int c=9; Pressing F8 does not make any difference. I wonder why the debugger stops with a blue arrow anyway. The same code is compiled and runs without problems in Alexandria. Thx. (also for pointing out the code block ...) Share this post Link to post
BKor 0 Posted November 20 22 hours ago, Anders Melander said: I would just use F8 (Step over) but it shouldn't make a difference. Where do you assign a value to c and where is pLayer (which I assume is a dynamic array) initialized? I think you need to show us some more code so we can make sense of what you are doing - and please use the code block. I was refused by "Clean Talk"... I will try to send code as .txt in attached file.... MelanderCode.txt Share this post Link to post
Anders Melander 1795 Posted November 21 (edited) 9 hours ago, BKor said: TForm1 *Form1; const int c=9; TBitmapLayer* pLayer[c]; int i,j=0; void __fastcall TForm1::FormCreate(TObject *Sender) { ... for(j = 0; j < c; j++) { pLayer[j] = new TBitmapLayer(Form1->ImageBackground->Layers); pLayer[j]->Bitmap->DrawMode = dmBlend; pLayer[j]->Scaled=true; } ... } I think I can see the problem: You are referencing the Form1 global variable before it has been assigned a value; Your code is in the constructor (or more precisely: an event handler called from the constructor) and the Form1 value isn't assigned until the constructor returns. Do like this instead: void __fastcall TForm1::FormCreate(TObject *Sender) { ... for(j = 0; j < c; j++) { pLayer[j] = new TBitmapLayer(this->ImageBackground->Layers); pLayer[j]->Bitmap->DrawMode = dmBlend; pLayer[j]->Scaled=true; } ... } or simply: void __fastcall TForm1::FormCreate(TObject *Sender) { ... for(j = 0; j < c; j++) { pLayer[j] = new TBitmapLayer(ImageBackground->Layers); pLayer[j]->Bitmap->DrawMode = dmBlend; pLayer[j]->Scaled=true; } ... } Of course it would be best if you could avoid all those global variables (not Form1 but all the others). I don't know if they were just there for debugging this problem. Edited November 21 by Anders Melander Share this post Link to post
BKor 0 Posted November 21 13 hours ago, Anders Melander said: I think I can see the problem: You are referencing the Form1 global variable before it has been assigned a value; Your code is in the constructor (or more precisely: an event handler called from the constructor) and the Form1 value isn't assigned until the constructor returns. Do like this instead: void __fastcall TForm1::FormCreate(TObject *Sender) { ... for(j = 0; j < c; j++) { pLayer[j] = new TBitmapLayer(this->ImageBackground->Layers); pLayer[j]->Bitmap->DrawMode = dmBlend; pLayer[j]->Scaled=true; } ... } or simply:...... Of course it would be best if you could avoid all those global variables (not Form1 but all the others). I don't know if they were just there for debugging this problem. I have tried both suggestions, but that did not make any difference. The debugger again stops with a blue arrow at the loop line. If I press F8 to go to the next line of code - a blue arrow goes to the end of void __fastcall TForm1::FormCreate(TObject *Sender) - as before. Thx! Share this post Link to post
Anders Melander 1795 Posted November 21 And did you replace all the Form1-> with this-> ? Share this post Link to post
BKor 0 Posted November 21 1 hour ago, Anders Melander said: And did you replace all the Form1-> with this-> ? Yes, I did. I have a feeling that if I would newly rewrite the same code in Athens - that it would work normally (as it does in Alexandria). I will try that tomorrow and let you know... Share this post Link to post
Anders Melander 1795 Posted November 21 32 minutes ago, BKor said: I have a feeling that if I would newly rewrite the same code in Athens - that it would work normally (as it does in Alexandria). Sounds like a good plan. But please use version numbers instead of marketing names. I have no idea what versions Athens or Alexandria refers to - nor do I care to know. Share this post Link to post
BKor 0 Posted November 22 20 hours ago, Anders Melander said: Sounds like a good plan. But please use version numbers instead of marketing names. I have no idea what versions Athens or Alexandria refers to - nor do I care to know. I was wrong. Rewriting the code in RadStudio 12 did not work. When compiling it gives: Access violation at address 6CE9D636 in module 'rtl290.bpl' (offset 11D636). Read at address 006C005E. When debugging it stops at loop, as before. I would like to delete some of my previous messages (ones with tons of images), is this possible? Share this post Link to post
Anders Melander 1795 Posted November 22 10 minutes ago, BKor said: When compiling it gives: Access violation at address 6CE9D636 in module 'rtl290.bpl' (offset 11D636). Read at address 006C005E. Are you saying that you get an exception when compiling the code? I think you mean when running the code. Going back and looking at your screenshots, I can see that the exception probably occurs in some paint code. That's why you get the cascading errors. A repaint causes an error which triggers a new repaint which causes an error, etc. etc. 2 minutes ago, BKor said: I was wrong. Rewriting the code in RadStudio 12 did not work. If you can reduce the project to the smallest possible case that reproduces the problem and post the code in a zip file, then maybe some of those here that actually use C++ (I don't) can have a go at it. For example, if you remove all the 3rd party stuff (including Graphics32), can you still reproduce the problem? 4 minutes ago, BKor said: I would like to delete some of my previous messages (ones with tons of images), is this possible? No. Share this post Link to post
BKor 0 Posted November 22 Yes, I mean running the code. I will remove the 3rd party stuff and see what happens. And then also reinstall the 3rd parties. Thx... Share this post Link to post
Remy Lebeau 1405 Posted November 23 (edited) On 11/21/2024 at 11:49 AM, BKor said: If I press F8 to go to the next line of code - a blue arrow goes to the end of void __fastcall TForm1::FormCreate(TObject *Sender) - as before. A word of advice - in C++, NEVER use the Form's OnCreate and OnDestroy events! (they are perfectly safe to use in Delphi only). The events are based on Delphi's object creation model (derived classes created before base classes), which is different than C++'s creation model (base classes created before derived classes). Also, their behavior has changed a few times over the years (due to internal changes [and bugs] related to handling of the TForm.OldCreateOrder property), so they are not always consistent in C++. As such, the events can be called before the Form's C++ constructor and after its destructor, respectively (I've seen it happen), which leads to undefined behavior in C++. In C++, ALWAYS use the Form's actual constructor/destructor instead. Edited November 23 by Remy Lebeau 4 Share this post Link to post
Anders Melander 1795 Posted November 23 Well, that would certainly explain the symptoms we're seeing. Share this post Link to post
BKor 0 Posted November 24 On 11/23/2024 at 7:40 AM, Remy Lebeau said: In C++, ALWAYS use the Form's actual constructor/destructor instead. If it is not too much, can I kindly ask you if you can show me how to ( in a simple example?), use the Form's actual constructor/destructor in c++ builder? Share this post Link to post
Remy Lebeau 1405 Posted November 24 (edited) 1 hour ago, BKor said: If it is not too much, can I kindly ask you if you can show me how to ( in a simple example?), use the Form's actual constructor/destructor in c++ builder? Like this: class TForm1 : public TForm { ... private: static const int c = 9; TBitmapLayer* pLayer[c]; public: __fastcall TForm1(TComponent *Owner); __fastcall ~TForm1(); ... }; __fastcall TForm1::TForm1(TComponent *Owner) : TForm(Owner) { ... for(int j = 0; j < c; ++j) { pLayer[j] = new TBitmapLayer(ImageBackground->Layers); pLayer[j]->Bitmap->DrawMode = dmBlend; pLayer[j]->Scaled = true; ... } ... } __fastcall TForm1::~TForm1() { ... for(int j = 0; j < c; ++j) { delete pLayer[j]; } ... } Edited November 24 by Remy Lebeau Share this post Link to post