⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch22.htm

📁 好书《C++ Builder高级编程技术》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
// us to have multiple functions all called `Register'.


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

#if !defined(BCB_NAMESPACES)

#define BCB_NAMESPACES

#endif

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

// Include DSTRING.H - Defines 
AnsiString support class

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

#include <vcl\dstring.h>

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

// The following are expanded inline 
to avoid pulling in the headers

// and lengthen the compilation time when rebuilding the palette.

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

typedef void* HINSTANCE;

#if !defined(WINAPI)

#define WINAPI __stdcall


#endif

#if !defined(DLL_PROCESS_ATTACH)

#define DLL_PROCESS_ATTACH 1

#endif

#if !defined(DLL_THREAD_ATTACH)

#define DLL_THREAD_ATTACH  2

#endif

#if !defined(DLL_THREAD_DETACH)

#define DLL_THREAD_DETACH  3

#endif

#if 
!defined(DLL_PROCESS_DETACH)

#define DLL_PROCESS_DETACH 0

#endif

namespace Libmain {

typedef void __fastcall (*TRegisterProc)(void);

extern  void __fastcall RegisterModule(const System::AnsiString Name, 

  TRegisterProc RegisterProc);

}

using 
namespace Libmain;

namespace System {

extern void __cdecl ProcessAttachTLS(void);

extern void __cdecl ProcessDetachTLS(void);

extern void __cdecl ThreadAttachTLS(void);

extern void __cdecl ThreadDetachTLS(void);

}

using namespace System;


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

// Prototype for each component's `Register routine. Followed

// by instruction to have linker pull in the OBJ. module which

// implements the Register routine.

//

//  
Each component is expected to provide a routine with the

//  following signature:

//

//       extern void __fastcall Register(void);

//

//  This routine must be in a namespace which matches the

//  name of the component itself. Therefore, the 
routine is

//  actually prototyped as:

//

//       namespace Componentname {

//           extern void __fastcall Register(void);

//       };

//

//  Note The namespace must be in all lowercase characters

//        except for the first one. i.e. 
Namespacename.

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

namespace Stdreg { extern void __fastcall Register(void); }

namespace Dbreg { extern void __fastcall Register(void); }

namespace Isp { extern void 
__fastcall Register(void); }

namespace Sysreg { extern void __fastcall Register(void); }

namespace Quickrep { extern void __fastcall Register(void); }

namespace Ocxreg { extern void __fastcall Register(void); }

namespace Olereg { extern void 
__fastcall Register(void); }

namespace Ddereg { extern void __fastcall Register(void); }

namespace Chartfx { extern void __fastcall Register(void); }

namespace Vcfimprs { extern void __fastcall Register(void); }

namespace Vcfrmla1 { extern void 
__fastcall Register(void); }

namespace Vcspell { extern void __fastcall Register(void); }

namespace Graphsvr { extern void __fastcall Register(void); }

namespace Ibreg { extern void __fastcall Register(void); }

namespace Win31reg { extern void 
__fastcall Register(void); }

namespace Sampreg { extern void __fastcall Register(void); }

namespace Unleash1 { extern void __fastcall Register(void); }

// (Search Path for Components (.CPP, .PAS, .OBJ & .LIB)

//  => 
g:\bcb\LIB;g:\bcb\LIB\OBJ;g:\srcc\punleash\utils

//

// Added to search paths: g:\bcb\LIB

// Added to search paths: g:\bcb\LIB\OBJ

// Added to search paths: g:\srcc\punleash\utils

// Added to project: g:\bcb\bin\cmplib32.cpp FileType: SRC

// 
Added to project: bcbmm.lib FileType: LIB

#pragma resource   "StdReg.dcr"  // Link dcr of standard module "StdReg"

// Added to project: g:\bcb\LIB\OBJ\DBReg.obj (From SearchPath) FileType: OBJ

// Added to project: 
g:\bcb\LIB\OBJ\DBReg.dcr (From SearchPath) FileType: RES

#pragma resource      "ISP.dcr"  // Link dcr of standard module "ISP"

#pragma resource   "SysReg.dcr"  // Link dcr of standard module "SysReg"

#pragma 
resource "Quickrep.dcr"  // Link dcr of standard module "Quickrep"

#pragma resource   "OLEReg.dcr"  // Link dcr of standard module "OLEReg"

#pragma resource   "DDEReg.dcr"  // Link dcr of standard 
module "DDEReg"

#pragma resource  "ChartFX.dcr"  // Link dcr of standard module "ChartFX"

#pragma resource "VCFImprs.dcr"  // Link dcr of standard module "VCFImprs"

#pragma resource 
"VCFrmla1.dcr"  // Link dcr of standard module "VCFrmla1"

#pragma resource  "VCSpell.dcr"  // Link dcr of standard module "VCSpell"

#pragma resource "GraphSvr.dcr"  // Link dcr of standard module 
"GraphSvr"

#pragma resource    "IBReg.dcr"  // Link dcr of standard module "IBReg"

#pragma resource "Win31Reg.dcr"  // Link dcr of standard module "Win31Reg"

#pragma resource  
"SampReg.dcr"  // Link dcr of standard module "SampReg"

// Added to project: g:\srcc\punleash\utils\Unleash1.cpp 

//  (From SearchPath) FileType: SRC

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


// Routine which registers the various modules implementing components

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

bool

InitCmpLib()

{

  RegisterModule("StdReg", Stdreg::Register);

  
RegisterModule("DBReg", Dbreg::Register);

  RegisterModule("ISP", Isp::Register);

  RegisterModule("SysReg", Sysreg::Register);

  RegisterModule("Quickrep", Quickrep::Register);

  
RegisterModule("OCXReg", Ocxreg::Register);

  RegisterModule("OLEReg", Olereg::Register);

  RegisterModule("DDEReg", Ddereg::Register);

  RegisterModule("ChartFX", Chartfx::Register);

  
RegisterModule("VCFImprs", Vcfimprs::Register);

  RegisterModule("VCFrmla1", Vcfrmla1::Register);

  RegisterModule("VCSpell", Vcspell::Register);

  RegisterModule("GraphSvr", Graphsvr::Register);

  
RegisterModule("IBReg", Ibreg::Register);

  RegisterModule("Win31Reg", Win31reg::Register);

  RegisterModule("SampReg", Sampreg::Register);

  RegisterModule("Unleash1", Unleash1::Register);

  return true;

}


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

// Library's entry point

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

extern "C"

int WINAPI

DllEntryPoint(HINSTANCE 
/*hInstance*/, unsigned long reason, void*)

{

  switch (reason) {

    case DLL_PROCESS_ATTACH:

       ProcessAttachTLS();

       InitCmpLib();

       break;

    case DLL_PROCESS_DETACH:

       ProcessDetachTLS();

       break;

    case 
DLL_THREAD_ATTACH:

       ThreadAttachTLS();

       break;

    case DLL_THREAD_DETACH:

       ThreadDetachTLS();

       break;

  }

  return 1;



}

</FONT></PRE>
<P>To understand the unit, start at the bottom, with the <TT>DllEntryPoint</TT> 
function.
This routine is called when Windows first loads the DLL into memory and each time
it is accessed by a BCB thread. <TT>ProcessAttachTLS</TT> and related routines are
all part of the internal system code. This code is none of our business, so 
we can
safely &quot;pay no attention to the man behind the curtain.&quot;</P>
<P><TT>InitCmpLib</TT> calls the <TT>Register</TT> method for each of the modules
used in the project. If you look at the bottom of the list, you will see where the

<TT>Register</TT> method for <TT>Unleash1</TT> is listed. You might think that we
don't have enough calls in this section to create the over 100 components found on
the Component Palette. The issue here is that some of the <TT>Register</TT> methods

register 20 or 30 different components at one shot. Here, for example, is the <TT>Register</TT>
method from <TT>StdReg.pas</TT>:</P>
<PRE><FONT COLOR="#0066FF">procedure Register;

begin

  RegisterComponents(LoadStr(srStandard), [TMainMenu, 
TPopupMenu, TLabel,

    TEdit, TMemo, TButton, TCheckBox, TRadioButton, TListBox, TComboBox,

    TScrollBar, TGroupBox, TRadioGroup, TPanel]);

  RegisterComponents(LoadStr(srAdditional), [TBitBtn, TSpeedButton,

    TMaskEdit, TStringGrid, 
TDrawGrid, TImage, TShape, TBevel,

    TScrollBox]);

  RegisterComponents(LoadStr(srWin95), [TTabControl, TPageControl,

    TTreeView, TListView, TImageList, THeaderControl, TRichEdit,

    TStatusBar, TTrackBar, TProgressBar, TUpDown, THotKey]);

  
RegisterClasses([TTabSheet]);

  RegisterNoIcon([TMenuItem]);

  RegisterComponentEditor(TMenu, TMenuEditor);

  RegisterComponentEditor(TImage, TGraphicEditor);

  RegisterComponentEditor(TPageControl, TPageControlEditor);

  
RegisterComponentEditor(TTabSheet, TPageControlEditor);

  RegisterComponentEditor(TImageList, TImageListEditor);

  RegisterPropertyEditor(TypeInfo(string), 

    TCustomMaskEdit, `EditMask', TMaskProperty);

  
RegisterPropertyEditor(TypeInfo(string), 

    TCustomMaskEdit, `Text', TMaskTextProperty);

  RegisterPropertyEditor(TypeInfo(TTabSheet), TPageControl, `ActivePage',

    TActivePageProperty);

  RegisterPropertyEditor(TypeInfo(TStatusPanels), nil, 
`', 

    TStatusPanelsProperty);

  RegisterPropertyEditor(TypeInfo(THeaderSections), nil, `', 

    THeaderSectionsProperty);

  RegisterPropertyEditor(TypeInfo(TListColumns), nil, `', 

    TListColumnsProperty);

  
RegisterPropertyEditor(TypeInfo(TListItems), nil, `', 

    TListItemsProperty);

  RegisterPropertyEditor(TypeInfo(TTreeNodes), nil, `', 

    TTreeNodesProperty);

</FONT></PRE>
<PRE><FONT COLOR="#0066FF">end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -