Pregunta

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;
¿Fue útil?

Solución

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top