-1

I have two forms called fmMain and fmEmpl. Both have each TStatusBar called sbMain and sbEmpl. I have a TDataModule called dmData to store the database components.

I need to update the sbEmpl panels so it can displays actual values from the database when the cell grid is highlighted. I've been try to use the TClientDataSet's OnAfterScroll handler to handling this event but it just working on fmMain only, not with fmEmpl. It always raising error message if I try to update the sbEmpl panels. This is the message:

Access violation at address 00405337 in module 'SpeZet.exe'. Read of address 0000038C.

Whereas, I have including both header (.h) on dmData.

What going wrong with TStatusBar here?

Any idea?

Thank a lot in advance.

EDIT : Ok, here is the code:

void __fastcall TdmData::cdsEmplAfterScroll(TDataSet *DataSet)
{

    vEmpl = "Name = " +
            dmData->cdsEmpl->FieldByName("Name")->AsString +
            " | idEmployee = " +
            dmData->cdsEmpl->FieldByName("idEmployee")->AsInteger +
            " | idJob  = " +
            dmData->cdsEmpl->FieldByName("idJob")->AsInteger;

    fmMain->sbMain->SimplePanel = true;
    fmMain->sbMain->SimpleText = vEmpl;
    fmEmpl->sbEmpl->SimplePanel = true;
    fmEmpl->sbEmpl->SimpleText = vEmpl;
}

The "Access Violation" message is raised at line:

fmEmpl->sbEmpl->SimplePanel = true;
fmEmpl->sbEmpl->SimpleText = vEmpl;
Jessie M
  • 498
  • 1
  • 9
  • 23

2 Answers2

2

Most probably your datamodule doesn't have a valid pointer to your fbEmpl form.

Riho
  • 4,523
  • 3
  • 33
  • 48
  • I have adding "#include "uEmployee.h" line at the top of dmData.cpp .. Is the header file already handling the pointer to all component installed in fmEmpl? – Jessie M Apr 01 '13 at 05:27
  • header file just helps your datamodule to understand what is this uEmployee class. Where have you actually created your form (with fmEmpl=new .... )? – Riho Apr 01 '13 at 07:19
  • I manually create the fmEmpl with pick File >> New >> Form - C++ Builder from the compiler menu.. – Jessie M Apr 01 '13 at 07:25
  • That's designing your form. But in runtime you have to use the "new" to create the form. Try to browse around the sample projects and see how creating forms is handled- – Riho Apr 01 '13 at 07:46
  • So, what the actual connection between `FormCreate` using `new` and this problem? Is the `FormCreate` affect the "Access Violation"? – Jessie M Apr 01 '13 at 09:34
  • Without the code it's impossible to know what you are doing wrong. Use the debugger to see if you have valid fmEmpl pointer when you are trying to access it's statusbar. – Riho Apr 01 '13 at 18:58
  • How to check the form validation as you mean? – Jessie M Apr 02 '13 at 04:35
0

Finally, based on this article, I have solve this problem.. I didn't notice that dmData is created before the fmEmpl so it will raising any "Access Violation" error message when I try to access the fmEmpl.

I make simple condition to check if fmEmpl was created or yet. This is the condition:

if (fmEmpl != NULL) {
    sbEmpl->SimplePanel = true;
    sbEmpl->SimpleText = sData;
}

Now, I can accessing and updating the sbEmpl directly from dmData.

Thanks.

Jessie M
  • 498
  • 1
  • 9
  • 23
  • You marked your own answer as correct when @Riho was the first person to be correct and I asked in the comments section of the question. You did not have a valid pointer and that was causing the error. – Gregor Brandt Apr 02 '13 at 14:52
  • @GregorBrandt Ok, I have corrected my mark.. I didn't really noticed that Riho's answer was related to my own answer.. Please cancel your minus mark.. Thanks. – Jessie M Apr 03 '13 at 03:11
  • can't removed, its been 23 hours and is now locked in unless you edit the answer. – Gregor Brandt Apr 03 '13 at 14:45