コンポーネントの作成と登録(ダイアログ ボックス)

提供: RAD Studio
移動先: 案内検索

ダイアログボックスのコンポーネント化:インデックス への移動

すべてのコンポーネントの作成を同じように開始します。ユニットの作成、コンポーネント クラスの派生、登録、コンパイル、ツール パレットへのインストールを行います。このプロセスの概要については、「新しいコンポーネントの作成」を参照してください。

たとえば、次の仕様に従って、コンポーネント作成の一般的な手順を実行します。

  • コンポーネントのユニットを AboutDlg と呼びます。
  • TComponent から TAboutBoxDlg という新しいコンポーネント タイプを派生させます。
  • ツール パレットの [Samples] ページに TAboutBoxDlg を登録します。

その結果、ユニットは次のようになります。



 unit AboutDlg;
 interface
 uses
   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms;
 type
   TAboutBoxDlg = class(TComponent)
   end;
 procedure Register;
 implementation
 procedure Register;
 begin
   RegisterComponents('Samples', [TAboutBoxDlg]);
 end;
 end.



 #include <vcl\vcl.h>
 #pragma hdrstop
 #include "AboutDlg.h"
 //---------------------------------------------------------------------------
 #pragma package(smart_init);
 //---------------------------------------------------------------------------
 static inline TAboutBoxDlg *ValidCtrCheck()
 {
   return new TAboutBoxDlg(NULL);
 }
 //---------------------------------------------------------------------------
 namespace AboutDlg {
 {
   void __fastcall PACKAGE Register()
   {
     TComponentClass classes[1] = {__classid(TAboutBoxDlg)};
     RegisterComponents("Samples", classes, 0);
   }
 }



 #ifndef AboutDlgH
 #define AboutDlgH
 //---------------------------------------------------------------------------
 #include <vcl\sysutils.hpp>
 #include <vcl\controls.hpp>
 #include <vcl\classes.hpp>
 #include <vcl\forms.hpp>
 //---------------------------------------------------------------------------
 class PACKAGE TAboutBoxDlg : public TComponent
 {
 private:
 protected:
 public:
 __published:
 };
 //---------------------------------------------------------------------------
 #endif



新しいコンポーネントには、TComponent に組み込まれた機能しかありません。最も単純な非ビジュアル コンポーネントになっています。次のセクションでは、コンポーネントとダイアログ ボックスとの間のインターフェイスを作成します。