Zahir Saleh
2008-06-23 07:22:30 UTC
Hello,
I had earlier inquired about exe icon disapering when i usen my personal component. Here is the code for the component. Please assist....note: I am not very familiar with component creation...
//---------------------------------------------------------------------------
#ifndef ToggleSwitchH
#define ToggleSwitchH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TToggleSwitch : public TCustomPanel
{
enum TStates { stOn,stOff };
typedef void __fastcall (__closure *TMyClick)(TObject *Sender, TStates State);
private:
TMyClick FOnMyClick;
TStates FState;
TColor FColorOff;
TColor FColorOn;
String FDeviceName;
void __fastcall SetState(TStates Value);
void __fastcall SetOffColor(TColor Value);
void __fastcall SetOnColor(TColor Value);
void __fastcall SetDeviceName(String Value);
protected:
DYNAMIC void __fastcall DblClick();
void __fastcall RaiseClickEvent(TObject* Sender);
void __fastcall Resized(TObject *Sender);
void __fastcall TabClick(TObject *Sender);
void __fastcall ToggleState();
TButton *SwitchPanel;
void __fastcall Paint();
public:
__fastcall TToggleSwitch(TComponent* Owner);
__fastcall ~TToggleSwitch();
__published:
__property TMyClick OnStateChange = {read=FOnMyClick, write=FOnMyClick};
__property Font;
__property TStates State = {read=FState, write=SetState, default = stOn};
__property TColor OffColor = {read=FColorOff, write=SetOffColor,default = clRed};
__property TColor OnColor = {read=FColorOn, write=SetOnColor,default = clLime};
__property String DeviceName= {read=FDeviceName, write=SetDeviceName, nodefault};
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
//=========the header file .h ends here================
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <ToggleSwitch.h>
#pragma package(smart_init)
#pragma resource "ToggleSwitch.res"
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TToggleSwitch *)
{
new TToggleSwitch(NULL);
}
//---------------------------------------------------------------------------
__fastcall TToggleSwitch::TToggleSwitch(TComponent* Owner)
: TCustomPanel(Owner)
{
SwitchPanel = new TButton(this);
SwitchPanel->Parent = this;
SwitchPanel->Caption = "ON";
SwitchPanel->OnClick = RaiseClickEvent;//;OnDblClick;
SwitchPanel->Font->Size = 8;
SwitchPanel->Font->Pitch = fpFixed;
SwitchPanel->Font->Style = TFontStyles()<< fsBold;
//-------------------------
FColorOff = clRed;
FColorOn = clLime;
Color = clLime;
BevelInner = bvLowered;
BevelOuter = bvNone;
FState = stOn;
Width = 28;
Height = 49;
Caption = " ";
SwitchPanel->Width = Width;
OnResize = Resized;
}
//---------------------------------------------------------------------------
__fastcall TToggleSwitch::~TToggleSwitch()
{
}
//---------------------------------------------------------------------------
namespace Toggleswitch
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TToggleSwitch)};
RegisterComponents("Jillion", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::DblClick()
{
ToggleState();
if( FOnMyClick )
FOnMyClick(this, FState);
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::RaiseClickEvent(TObject* Sender)
{
ToggleState();
if( FOnMyClick )
FOnMyClick(this, FState);
}
//----------------------------------------------------------------------------
void __fastcall TToggleSwitch::ToggleState()
{
FState = !FState;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetState(TStates Value)
{
FState = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::Paint()
{
TabClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::TabClick(TObject *Sender)
{
switch(FState)
{
case stOn:
{
SwitchPanel->Top = Height-SwitchPanel->Height;
SwitchPanel->Caption = "OFF";
Color = FColorOff;
}
break;
case stOff:
{
SwitchPanel->Top = 0;
SwitchPanel->Caption = "ON";
Color = FColorOn;
}
break;
default:
break;
}
Caption = FDeviceName;
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetOffColor(TColor Value)
{
FColorOff = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetOnColor(TColor Value)
{
FColorOn = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::Resized(TObject *Sender)
{
SwitchPanel->Width = Width;
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetDeviceName(String Value)
{
FDeviceName = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
I had earlier inquired about exe icon disapering when i usen my personal component. Here is the code for the component. Please assist....note: I am not very familiar with component creation...
//---------------------------------------------------------------------------
#ifndef ToggleSwitchH
#define ToggleSwitchH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TToggleSwitch : public TCustomPanel
{
enum TStates { stOn,stOff };
typedef void __fastcall (__closure *TMyClick)(TObject *Sender, TStates State);
private:
TMyClick FOnMyClick;
TStates FState;
TColor FColorOff;
TColor FColorOn;
String FDeviceName;
void __fastcall SetState(TStates Value);
void __fastcall SetOffColor(TColor Value);
void __fastcall SetOnColor(TColor Value);
void __fastcall SetDeviceName(String Value);
protected:
DYNAMIC void __fastcall DblClick();
void __fastcall RaiseClickEvent(TObject* Sender);
void __fastcall Resized(TObject *Sender);
void __fastcall TabClick(TObject *Sender);
void __fastcall ToggleState();
TButton *SwitchPanel;
void __fastcall Paint();
public:
__fastcall TToggleSwitch(TComponent* Owner);
__fastcall ~TToggleSwitch();
__published:
__property TMyClick OnStateChange = {read=FOnMyClick, write=FOnMyClick};
__property Font;
__property TStates State = {read=FState, write=SetState, default = stOn};
__property TColor OffColor = {read=FColorOff, write=SetOffColor,default = clRed};
__property TColor OnColor = {read=FColorOn, write=SetOnColor,default = clLime};
__property String DeviceName= {read=FDeviceName, write=SetDeviceName, nodefault};
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
//=========the header file .h ends here================
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <ToggleSwitch.h>
#pragma package(smart_init)
#pragma resource "ToggleSwitch.res"
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TToggleSwitch *)
{
new TToggleSwitch(NULL);
}
//---------------------------------------------------------------------------
__fastcall TToggleSwitch::TToggleSwitch(TComponent* Owner)
: TCustomPanel(Owner)
{
SwitchPanel = new TButton(this);
SwitchPanel->Parent = this;
SwitchPanel->Caption = "ON";
SwitchPanel->OnClick = RaiseClickEvent;//;OnDblClick;
SwitchPanel->Font->Size = 8;
SwitchPanel->Font->Pitch = fpFixed;
SwitchPanel->Font->Style = TFontStyles()<< fsBold;
//-------------------------
FColorOff = clRed;
FColorOn = clLime;
Color = clLime;
BevelInner = bvLowered;
BevelOuter = bvNone;
FState = stOn;
Width = 28;
Height = 49;
Caption = " ";
SwitchPanel->Width = Width;
OnResize = Resized;
}
//---------------------------------------------------------------------------
__fastcall TToggleSwitch::~TToggleSwitch()
{
}
//---------------------------------------------------------------------------
namespace Toggleswitch
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TToggleSwitch)};
RegisterComponents("Jillion", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::DblClick()
{
ToggleState();
if( FOnMyClick )
FOnMyClick(this, FState);
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::RaiseClickEvent(TObject* Sender)
{
ToggleState();
if( FOnMyClick )
FOnMyClick(this, FState);
}
//----------------------------------------------------------------------------
void __fastcall TToggleSwitch::ToggleState()
{
FState = !FState;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetState(TStates Value)
{
FState = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::Paint()
{
TabClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::TabClick(TObject *Sender)
{
switch(FState)
{
case stOn:
{
SwitchPanel->Top = Height-SwitchPanel->Height;
SwitchPanel->Caption = "OFF";
Color = FColorOff;
}
break;
case stOff:
{
SwitchPanel->Top = 0;
SwitchPanel->Caption = "ON";
Color = FColorOn;
}
break;
default:
break;
}
Caption = FDeviceName;
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetOffColor(TColor Value)
{
FColorOff = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetOnColor(TColor Value)
{
FColorOn = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::Resized(TObject *Sender)
{
SwitchPanel->Width = Width;
}
//---------------------------------------------------------------------------
void __fastcall TToggleSwitch::SetDeviceName(String Value)
{
FDeviceName = Value;
Invalidate(); // repaints the component
}
//---------------------------------------------------------------------------