Delphi控件源码就是最好的示例了

解决方案 »

  1.   

    给你一个例子,一个具备URL的Label控件:
    unit SWURLLabel;interfaceuses
      Windows, Classes, Controls, StdCtrls, SysUtils, Forms,
      Graphics, ShellAPI;type
      TSWURLLabel = class(TLabel) // 从TLabel类派生
      private
        FOnBeforeExecuteURL: TNotifyEvent; // 指向执行URL之前要调用的过程    FURL: String;                      // URL字符串
        procedure SetURL(Value:String);
      protected
        procedure Click; override;         // 重载TLabel的Click方法
      public
        constructor Create(AOwner:TComponent); override; // 构造函数
        function ExecuteURL: Boolean; // 方法,执行URL
      published
        property OnBeforeExecuteURL: TNotifyEvent
          read FOnBeforeExecuteURL
          write FOnBeforeExecuteURL default nil;
        property OnExecuteURL: TNotifyEvent
          read FOnExecuteURL
          write FOnExecuteURL default nil;    property URL:String read FURL write SetURL;
      end;procedure Register;implementationconst DefaultURL:String = 'http://seawave.yeah.net';{ 重载TLabel的Click方法 }
    procedure TSWURLLabel.Click;
    begin
      inherited Click; // 执行TLabel的Click过程
      ExecuteURL;      // 调用ExecuteURL过程来执行URL
    end;{ 构造函数,初始化属性 }
    constructor TSWURLLabel.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);  // 首先调用父类的构造函数
      FURL := DefaultURL;        // URL属性值初始化为默认值
      Caption := DefaultURL;     // Caption
      Font.Color := clBlue;      // 颜色默认为蓝色  Font.Style := [fsUnderline]; // 字体默认为带下划线
      Cursor := crHandPoint;     // 光标形状默认为手掌形
    end;{ 方法,调用Windows API执行URL }
    function TSWURLLabel.ExecuteURL;
    var
      ZFileName:array[0..255] of char;
    begin
      if Assigned(FOnBeforeExecuteURL) then
        FOnBeforeExecuteURL(Self);  // 若指定了事件处理过程则调用它
      if Length(FURL)>0 then begin
        // 当URL不为空时执行
        StrPCopy(ZFileName, FURL);
        ShellExecute(Application.Handle, nil,
                     ZFileName, nil, nil, SW_SHOWNORMAL);  end;end;
    { 登记新构件的过程 }
    procedure Register;
    begin
      // 第一个参数是面板页的名字,第二个参数是新构件的类名
      RegisterComponents('SeaWave', [TSWURLLabel]);
    end;{ 私有方法,设置URL属性值 }
    procedure TSWURLLabel.SetURL(Value:String);
    begin
      FURL := Value;
      if csDesigning in ComponentState then
        Caption := Value;
    end;end.
      

  2.   

    在DELPHI5中有自己的例子,介绍如何做.而且在很多书中也很详细
      

  3.   

    只有直接编写源代码一种方法吗?有没有什么可视化的方法,事实上我只是想把一个常用的小的模块作为一个整体,涉及到DBGird,Tedit.Tbutton,又没有什么简单的实现方法??
      

  4.   

    一本<<Component Write Guide>>上次我下了,还可以吧
      

  5.   

    一本<<Component Write Guide>>上次我下了,还可以吧