Board index » cppbuilder » My event handlers don't appear in the object inspector

My event handlers don't appear in the object inspector

Here is the header:

#ifndef ABSTRACT_DATA_FORM_HANDLE_H
#define ABSTRACT_DATA_FORM_HANDLE_H

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>

class CBlock;

class TDataForm : public TForm {
__published: // IDE-managed Components
    void __fastcall KeyPressFloat(TObject *Sender, char &Key);
    void __fastcall KeyPressInt(TObject *Sender, char &Key);
    void __fastcall KeyPressUnsignedInt(TObject *Sender, char &Key);
  public:
    // have same constructor signatures as TForm, and just dispatch
    // constructor call to the appropriate constructor in TForm
    __fastcall TDataForm(Classes::TComponent* AOwner)
        : TForm(AOwner) { }
    __fastcall TDataForm(Classes::TComponent* AOwner, int Dummy)
        : TForm(AOwner, Dummy) { }
    __fastcall TDataForm(HWND ParentWindow)
        : TForm(ParentWindow) { }
    virtual bool Setup(CBlock*) = 0;
    virtual bool OK(void) = 0;
    virtual bool ResetBlockData(CBlock*) = 0;

Quote
};

#endif

And here is the implementation file:
#include "DataFormHandle.h"

void __fastcall TDataForm::KeyPressFloat(TObject *Sender, char &Key) {
  if (isdigit(Key) ||
      (Key == '.') ||
      (Key == '-') ||
      (Key == 'e') ||
      (Key == 'E')) return;
  Key = 0;

Quote
};

void __fastcall TDataForm::KeyPressInt(TObject *Sender, char &Key) {
  if (isdigit(Key) || (Key == '-')) return;
  Key = 0;

Quote
};

void __fastcall TDataForm::KeyPressUnsignedInt(TObject *Sender, char &Key) {
  if (isdigit(Key)) return;
  Key = 0;

Quote
};

And now here is the header for one of the child forms:

//--------------------------------------------------------------------------
-

#ifndef IndoorAirFormH
#define IndoorAirFormH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

#include "DataFormHandle.h"

//--------------------------------------------------------------------------
-
class TIndoorAirDataForm : public TDataForm
{
__published: // IDE-managed Components
  TLabel *WaterVolatilizationRateLBL;
  TLabel *ExchangeRateLBL;
  TLabel *AttenuationCoefficientLBL;
  TEdit *WaterVolatilizationRateEDT;
  TEdit *ExchangeRateEDT;
  TEdit *AttenuationCoefficientEDT;
  TButton *okBTN;
  TButton *cancelBTN;
  void __fastcall okBTNClick(TObject *Sender);
  void __fastcall cancelBTNClick(TObject *Sender);
private: // User declarations
  long double WaterVolatilizationRate,
              ExchangeRate,
              AttenuationCoefficient;
  bool        OKbtnPressed;
  bool ValidateTheData(void);
  void ConvertTheData(void);
public:  // User declarations
  __fastcall TIndoorAirDataForm(TComponent* Owner);
  bool Setup(CBlock*);
  bool OK(void);
  bool ResetBlockData(CBlock*);

Quote
};

//--------------------------------------------------------------------------
-
extern PACKAGE TIndoorAirDataForm *IndoorAirDataForm;
//--------------------------------------------------------------------------
-

I found that none of my keypress event handlers appear in the object
inspector as candidate event handlers for the instances of TEdit on this (or
any similarly derived) form.  Instead I had to set the event handler
manually in the constructor, as follows:

__fastcall TIndoorAirDataForm::TIndoorAirDataForm(TComponent* Owner)
  : TDataForm(Owner), OKbtnPressed(false)
{
  WaterVolatilizationRateEDT->OnKeyPress = KeyPressFloat;
  ExchangeRateEDT->OnKeyPress = KeyPressFloat;
  AttenuationCoefficientEDT->OnKeyPress = KeyPressFloat;

Quote
}

While the program is working as expected, I do not understand why the event
handlers I provide in the abstract base class (derived from TForm) are not
available in the derived classes.  Is this something that can be fixed?

Cheers,

Ted

 

Re:My event handlers don't appear in the object inspector


Thanks Gambit,

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> wrote in message
news:3d877e00$1@newsgroups.borland.com...

Quote
> The Object Inspector only displays the event handlers that are declared in
> the actual form that is being displayed in the Inspector, not those of its
> base class.

OK.  That explains why they aren't visible in the object inspector.

Quote
> You should move your KeyPress handlers into 'private' instead of
> '__published' (since they do you no good as published anyway, for the
reason
> above), and define actual handlers for the Edit fields themselves using
the
> Object Inspector as normal.

Well, not quite.  If they are private, they will not be accessable in the
derived class.  They ought to be protected instead.

I can live with having to either create additional event handlers in each
derived class that dispatches the call to one of my event handlers in the
base class, or simply assigning the appropriate event handlers in the form
constructor (which strikes me as a bit cleaner and more maintainable), until
I find a better way.  We're under pressure to get yet another product out
the door ASAP, so there's little time for testing different methods.

Thanks,

Ted

Other Threads