📄 mainform.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainForm.h"
#include <typeinfo>
#include "TestForm.h"
#include <JclRTTI.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "JvComponent"
#pragma link "JvExControls"
#pragma link "JvInspector"
#pragma link "JvInspExtraEditors"
#pragma resource "*.dfm"
TfrmMain *frmMain;
typedef enum
{
toOption1,
toOption2,
toOption3,
toOption4,
toOption5,
toOption6,
toOption7,
toOption8
} TTestOption;
typedef Set<TTestOption, toOption1, toOption8> TTestOptions;
typedef Shortint TTestRange;
typedef enum
{
teNone,
teAtLeastOne,
teAtMostTwo,
teUnlimited
} TTestEnum ;
// JvInspector.hpp provides a TypeInfo helper class for most common
// types but the types that we defined locally are of course not taken
// into account. So we declare a class that will be used to gather
// the type info for various types defined in this file
class TLocalTypeInfoHelper: public TJvTypeInfoHelper
{
private:
TTestOptions FTTestOptionsProp;
TTestEnum FTTestEnumProp;
TTestRange FTTestRangeProp;
__published:
__property TTestOptions TTestOptionsProp = {read=FTTestOptionsProp};
__property TTestEnum TTestEnumProp = {read=FTTestEnumProp};
__property TTestRange TTestRangeProp = {read=FTTestRangeProp};
};
// Some global variables. They may as well be static members
// of TfrmMain, but to remain consistent with the Delphi example,
// we left them here
static PTypeInfo GeneratedTestEnum = JclGenerateEnumType("TestEnum",
OPENARRAY(AnsiString,("me, myself and I", "Marcel Bestebroer", "Project JEDI", "JEDI-VCL Inspector")));;
static AnsiString FirstName = "Marcel";
static AnsiString Initial;
static AnsiString LastName = "Bestebroer";
static AnsiString VerInfoStr = JVCL_VERSIONSTRING;
static TDateTime ADate = Now();
static TImageIndex ImgIdx;
// We need to emulate the initialization section of Delphi units so
// that we can register some specialized type inspectors
// The only way is to declare a dummy class with the initialization
// code in its constructor and the finalization code in its destructor.
// Then we declare a static variable instance of that class and that
// will do a work similar to the initialization and finalization
// sections of a Delphi unit.
// Please note that this is a construct that should be avoided as
// much as possible as it keeps a useless object in memory during the
// whole life of the project
class TInitializer
{
public:
TInitializer()
{
// Register the item inspectors from the Extra Inspector unit
TJvInspectorAlignItem::RegisterAsDefaultItem(__classid(TJvInspectorAlignItem));
TJvInspectorAnchorsItem::RegisterAsDefaultItem(__classid(TJvInspectorAnchorsItem));
TJvInspectorColorItem::RegisterAsDefaultItem(__classid(TJvInspectorColorItem));
TJvInspectorTImageIndexItem::RegisterAsDefaultItem(__classid(TJvInspectorTImageIndexItem));
// Register our TypeInfo helper class
RegisterTypeInfoHelper(__classid(TLocalTypeInfoHelper));
};
~TInitializer()
{
// You need the very latest CVS version for this not to provoke
// a linker error. (QC 7224)
RemoveTypeInfo(GeneratedTestEnum);
};
};
static TInitializer Initializer;
//--------------------------------------------------------------------
void __fastcall TfrmMain::AddInspectorSettings()
{
TJvInspectorCustomCategoryItem* InspCat;
int I;
const AnsiString PropArray[3][2] = {
{"UseBands", "Use bands"},
{"WantTabs", "TAB navigates"},
{"Painter", "Paint style"}
};
InspCat = new TJvInspectorCustomCategoryItem(JvInspector1->Root, NULL);
InspCat->DisplayName = "JvInspector Settings";
// The last argument to GetPropInfo is required by BCB5 and set to the same default value as found in BCB6
for (I = 0; I < 3; I++)
TJvInspectorPropData::New(__classid(TJvInspectorPropData), InspCat, JvInspector1, GetPropInfo(JvInspector1, PropArray[I][0], System::Set<Typinfo::TTypeKind, tkUnknown, tkDynArray>()))->DisplayName = PropArray[I][1];
TJvInspectorVarData::New(__classid(TJvInspectorVarData), InspCat, "AboutJVCL", TypeInfo(AnsiString), &VerInfoStr)->DisplayName = "About JVCL";
InspCat->Expanded = True;
}
void __fastcall TfrmMain::AddGlobalSettings()
{
TJvInspectorCustomCategoryItem* InspCat;
InspCat = new TJvInspectorCustomCategoryItem(JvInspector1->Root, NULL);
InspCat->DisplayName = "Global Settings (event based data)";
TJvInspectorEventData* data = dynamic_cast<TJvInspectorEventData*>(TJvInspectorEventData::New(__classid(TJvInspectorEventData), InspCat, "Use check marks", TypeInfo(bool))->Data);
data->OnGetAsOrdinal = GetBoolsAsChecks;
data->OnSetAsOrdinal = SetBoolsAsChecks;
InspCat->Expanded = True;
}
void __fastcall TfrmMain::AddFormAndControls()
{
TJvInspectorCustomCategoryItem* InspCat;
frmTest = new TfrmTest(this);
frmTest->Show();
Show();
InspCat = new TJvInspectorCustomCategoryItem(JvInspector1->Root, NULL);
InspCat->DisplayName = "Form and controls (published property data).";
InspCat->SortKind = iskNone;
AddCtrl(InspCat, frmTest);
AddCtrl(InspCat, frmTest->PanelForLabel);
AddCtrl(InspCat, frmTest->lblTest);
AddCtrl(InspCat, frmTest->Edit1);
InspCat->Expanded = true;
}
void __fastcall TfrmMain::AddCompoundTest()
{
TJvInspectorCustomCategoryItem* InspCat;
TJvInspectorCompoundItem* CompItem;
InspCat = new TJvInspectorCustomCategoryItem(JvInspector1->Root, NULL);
InspCat->DisplayName = "Compound items test (variable or heap data).";
CompItem = new TJvInspectorCompoundItem(InspCat, NULL);
CompItem->AddColumn(TJvInspectorVarData::New(__classid(TJvInspectorVarData), CompItem, "First", TypeInfo(AnsiString), &FirstName));
CompItem->AddColumn(TJvInspectorVarData::New(__classid(TJvInspectorVarData), CompItem, "Initial", TypeInfo(AnsiString), &Initial));
CompItem->AddColumn(TJvInspectorVarData::New(__classid(TJvInspectorVarData), CompItem, "Last", TypeInfo(AnsiString), &LastName));
CompItem->Columns[0]->Width = 25;
CompItem->Columns[1]->Width = 15;
}
void __fastcall TfrmMain::AddCtrl(TJvCustomInspectorItem* Parent, TControl* Ctrl)
{
TJvInspectorCustomCategoryItem* InspCat;
// TNotifyEvent M;
InspCat = new TJvInspectorCustomCategoryItem(Parent, NULL);
InspCat->DisplayName = Ctrl->Name + ": " + Ctrl->ClassName(); // The cast to avoid a warning because ClassName is not a const method
if (Ctrl == frmTest->Edit1)
{
TJvInspectorTMethodItem* tmi = dynamic_cast<TJvInspectorTMethodItem*>(TJvInspectorPropData::New(__classid(TJvInspectorPropData), InspCat, Ctrl, "OnChange"));
tmi->AddInstance(frmTest, "frmTest");
tmi->AddInstance(this, "frmInspector");
// There is no way to directly convert from a TNotifyEvent
// to a TMethod
// So we need to do the job ourselves by getting the address
// using the method name.
// Then we set the Data member to the instance to which the
// method is to be applied
// Note 1: the method which name is to be retrieved MUST be
// published or MethodAddress will return NULL
// Note 2: the pointer used for Data MUST be point to a valid
// instance before being used here
// M = frmTest->Edit1Change1;
TMethod tmpMethod;
tmpMethod.Code = frmTest->MethodAddress("Edit1Change1");
tmpMethod.Data = frmTest;
tmi->AddMethod(tmpMethod, "Edit1Change1");
// M = Edit1Change2;
tmpMethod.Code = MethodAddress("Edit1Change2");
tmpMethod.Data = this;
tmi->AddMethod(tmpMethod, "Edit1Change2");
}
else
// The last argument is required by BCB5 but is not by BCB6
TJvInspectorPropData::New(__classid(TJvInspectorPropData), InspCat, Ctrl, System::Set<Typinfo::TTypeKind, tkUnknown, tkDynArray> ());
}
void __fastcall TfrmMain::AddINIFile()
{
TJvInspectorCustomCategoryItem* InspCat;
AnsiString IniFileName = ExtractFilePath(Application->ExeName);
IniFileName += "demo.ini";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -