Board index » cppbuilder » When is a Datamodule not a datamodule?

When is a Datamodule not a datamodule?

When it's a form, or so it appears.

I just returned to a project I haven't been using for around 3 weeks,
and suddenly all the datamodules look like forms.  They have the
alignment grid, display in button colour rather than window colour, and
have no caption.  Worse, every time I try to do anything with them (like
close the file in the editor ) I get the error message 'Error in module
MyFilename: Declaration of class TDataModule is missing or incorrect.'
And yes, it does say TDataModule, not my own class name.

Anyone seen anything like this before?  Any idea how to recover my
project?  Unfortunately, some smart person deleted all my old backups to
save disk space for new ones, and the last available backup is showing
the same behaviour.

AlisdairM

 

Re:When is a Datamodule not a datamodule?


Quote
: AlisdairM <"alisdair.meredith"@NO_SPAM_PLE...@benettonformula.com> wrote:
>I get the error message 'Error in module
>MyFilename: Declaration of class TDataModule is missing or incorrect.'

What are the first three lines of the TDataModule declaration (the one
starting with "class") and the five lines before that?

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:When is a Datamodule not a datamodule?


Quote
: AlisdairM <"alisdair.meredith"@NO_SPAM_PLE...@benettonformula.com> wrote:
>class TdmEmailResolution : public TDataModule
>{

Good, so this is not the problem.

What is the exact line where the TDataModule is referenced in the main
project file (this USE... thing)?

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:When is a Datamodule not a datamodule?


Quote
"Stefan Hoffmeister (TeamB)" wrote:
> What are the first three lines of the TDataModule declaration (the one
> starting with "class") and the five lines before that?

Thanks for looking in Stefan, here's the start of the header file

//---------------------------------------------------------------------------
#ifndef ModEmailResolutionH
#define ModEmailResolutionH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Db.hpp>
#include "FIBDatabase.hpp"
#include "FIBDataSet.hpp"
#include "FIBQuery.hpp"
#include "SMTPWinshoe.hpp"
#include "WinshoeMessage.hpp"
#include "Winshoes.hpp"
#include "fileio.hpp"
//---------------------------------------------------------------------------
class TdmEmailResolution : public TDataModule
{
__published:    // IDE-managed Components
        TWinshoeMessage *msgFaultAssignments;
        TWinshoeSMTP *mailFaultAssignments;
....

The include for Forms.hpp is implicit from the #include <vcl.h> in the
related .cpp file, but I tried adding it into this header without
success.

The only other time I have seen a similar problem was by adding the
PACKAGE macro to a class I wanted to export.  class and PACKAGE had to
be in the correct order!  This on has me stumped still.

For completeness sake, here's the top of the .cpp as well, in case it
becomes relevant.

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "ModEmailResolution.h"
//---------------------------------------------------------------------------
#include "DbModBenetton.h"
//---------------------------------------------------------------------------
#include "FormatUtils.h"
#include "FRSutils.h"
//---------------------------------------------------------------------------
#include "FIButils.h"         //      CFIBTransaction
#include "VCLutils.h"         //      CWaitCursor
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
#pragma link "FIBDatabase"
#pragma link "FIBDataSet"
#pragma link "FIBQuery"
#pragma link "SMTPWinshoe"
#pragma link "WinshoeMessage"
#pragma link "Winshoes"
#pragma link "fileio"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
TdmEmailResolution *dmEmailResolution;
//---------------------------------------------------------------------------
__fastcall TdmEmailResolution::TdmEmailResolution(TComponent* Owner)
        : TDataModule(Owner)
{

Quote
}

AlisdairM

Re:When is a Datamodule not a datamodule?


Quote
"Stefan Hoffmeister (TeamB)" wrote:
> What is the exact line where the TDataModule is referenced in the main
> project file (this USE... thing)?

USEFORM("ModEmailResolution.cpp", dmEmailResolution); /* TDataModule:
DesignClass */

and for completeness, here is the top of the .dfm file too ( I don't
browse them often enough to recognise all errors )

object DataModule: TDataModule
  Left = 539
  Top = 158
  Width = 233
  Height = 173
  Color = clBtnFace

Thanks again Stefan

AlisdairM

Re:When is a Datamodule not a datamodule?


The DFM file declaration is your problem.  It should look something like

object dmEmailResolution: TdmEmailResolution
  Left = 192
  Top = 114
  Height = 150
  Width = 215
  ...

For whatever reason the initial line that you posted would be a line for the
original TDataModle class and not a decendant.

Note that you will get some error messages about a property not existing if you
make the change and then do a view as form.  That is fine, it is just the form
properties like Color that don't exist on a DM.  The IDE will clean that out,
but warn you that it needs to do so.

Quote
AlisdairM wrote:

> "Stefan Hoffmeister (TeamB)" wrote:

> > What is the exact line where the TDataModule is referenced in the main
> > project file (this USE... thing)?

> USEFORM("ModEmailResolution.cpp", dmEmailResolution); /* TDataModule:
> DesignClass */

> and for completeness, here is the top of the .dfm file too ( I don't
> browse them often enough to recognise all errors )

> object DataModule: TDataModule
>   Left = 539
>   Top = 158
>   Width = 233
>   Height = 173
>   Color = clBtnFace

> Thanks again Stefan

> AlisdairM

--
Jeff Overcash (TeamB)   On waves of silver I dreamed of gold
(Please do not email    'Till I lost the peace that dreaming gives
 me directly unless     I dreamed of the moment of my own death
 asked.  Thank You)     That no one ever dreams and lives (Marillion)

Re:When is a Datamodule not a datamodule?


Quote
"Jeff Overcash (TeamB)" wrote:
> The DFM file declaration is your problem.  It should look something like

> object dmEmailResolution: TdmEmailResolution
>   Left = 192
>   Top = 114
>   Height = 150
>   Width = 215
>   ...

Thanks Jeff.  Fortunately (for me) I finally tracked down a backup from
Christmas Eve.  This is close to up-to-date on the parts of the project
that fouled up, so I am up and running again.  However, I have a backup
of the faulty project (in case I HAD lost too much, and it was easier to
battle with this way!) so I will go back and check this fix soon.  Once
I get a bug, I'm never happy ignoring them, I need them dead and I need
to know why!

I think this problem stems back to a flaky release of WinShoes (v7.038)
although I am upset that it managed to foul up the project quite so
badly.  Several components went missing from the modules in the process
too :? (

Quote
> Note that you will get some error messages about a property not existing if you
> make the change and then do a view as form.  That is fine, it is just the form
> properties like Color that don't exist on a DM.  The IDE will clean that out,
> but warn you that it needs to do so.

Yes, I've seen that before.  In fact, I'm quite pleased with the way the
IDE fixes up references in general.  Often, if I derive a superior class
from a VCL base, I will hack the .DFM to change the control types in the
form.  Next time I try to say, the IDE want to fix the .h for me.  A
much appreciated feature!

AlisdairM

Re:When is a Datamodule not a datamodule?


Hi,

I've had similar problem when using datamodule in dll (RTL, runtime
packages).

When I've created datamodule, declaration looked like this:

class TDataModule1 : public TDataModule
{
...

Quote
}

then I've change it to following:

class PACKAGE TDataModule1 : public TDataModule
{
...

Quote
}

and saved.
Voila! After loading back to ide datamodule's dfm is now TForm like!
(easy to replicate just create new dll & new datamodule, change it &save)

The solution for me is to change declaration to following:

class PACKAGE TDataModule1;

class TDataModule1 : public TDataModule
{
...

Quote
}

HTH.

Pavel S.

stejge...@tribut.ch

Other Threads