为什么要写组件?
写组件的心得和感想?
我现在想学习写组件,应从哪儿做起?

解决方案 »

  1.   

    1、现有组件不能满足要求
    2、oo的概念要很好
    3、先看oo的东西,再看VCL原代码
      

  2.   

    1:用组件方便
    2:要了解面向对象的机制
    3:了解windows的消息
      

  3.   

    可以发邮件[email protected]
      

  4.   

    overtime(空间在线) 
    哥哥,你说的好大概哟?
    能不能说具体点呢?
      

  5.   

    來學習學習...-------------------------------------
    http://www2.4tb.net/tghd.asp?name=dgfhz
      

  6.   

    我可是个写组件的高手,现在已经有了20多个自己写的组件了,其中有7,8个是重量级别的哦。我的20多个组件和函数库,如果谁想要请付钱200块,我发到你的MAIL里,我的MAIL是[email protected]
      

  7.   

    写组件通常是为了满足自己或项目的特殊需要,
    可以省去一些重复性的操作,将复杂的操作封装成一个组件,
    要写好组件关键是理解OOP的思想,同时对WIN API,算法要熟悉。
      

  8.   

    To Wush007  垃圾,跑到这里买弄啊!呵呵,看在我们多年同学的份上,给我一份吧!To 一楼的  说的轻巧,VCL源码你看懂了多少?
      

  9.   

    我自己改VCL然后把它们放在自己的目录里。
      

  10.   

    我前两天提问的一个贴子,谁能推荐几本专门介绍delphi组件开发方面的好书?
    http://expert.csdn.net/Expert/topic/2294/2294007.xml?temp=.2849542
    这是CDSoftwareWj(95927)兄给的答案:
    1.《Delphi5 程序员开发指南》 要看会消息处理部分和类部分
    2. 看VCL源代码
    3. 再看第三方开源组件源代码
    4. 都会了你就成达人了 hehe^^
    国内有几本书都是扫土的说说不痛不痒的,看了也白看.....
    也许你可以借鉴
      

  11.   

    你先要了解面向对象开发的实际应用
    对你开发软件的需求
    对WINDOWS的消息处理能力
    最后写出你想要的控件。
      

  12.   

    unit QFltEdit;interfaceuses
      Windows, Messages, SysUtils, Classes,StdCtrls,Controls,Forms;type
      TFloatEdit = class(TCustomEdit)
      private
        { Private declarations }
        FPrecision:Integer;
        FTextAlign:TAlignment;
        //procedure SetPrecision(value:Integer);
        procedure SetTextAlign(value:TAlignment);
        procedure WMChar(var Message: TWMChar); message WM_CHAR;
      protected
        { Protected declarations }
        function DoKeyPress(var Message: TWMKey): Boolean;
      public
        { Public declarations }
        constructor Create(AOwner:TComponent);override;
        procedure CreateParams(var Params: TCreateParams); override;
      published
        { Published declarations }
        property Precision:Integer read FPrecision write FPrecision default 2;
        property TextAlign:TAlignment read FTextAlign write SetTextAlign default taRightJustify;
        property Anchors;
        property AutoSelect;
        property AutoSize;
        property BorderStyle;
        property CharCase;
        property Color;
        property Constraints;
        property DragMode;
        property Enabled;
        property Font;
        property HideSelection;
        property MaxLength;
        property ParentColor;
        property ParentFont;
        property ParentShowHint;
        property PopupMenu;
        property ReadOnly;
        property ShowHint;
        property TabOrder;
        property TabStop;
        property Text;
        property Visible;
        property OnChange;
        property OnClick;
        property OnContextPopup;
        property OnDblClick;
        property OnDragDrop;
        property OnDragOver;
        property OnEndDrag;
        property OnEnter;
        property OnExit;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnStartDrag;
      end;
    procedure Register;
    implementation
    uses Tools;
    {
    VK_NUMPAD0 0 key (numeric keypad)
    VK_NUMPAD1 1 key (numeric keypad)
    VK_NUMPAD2 2 key (numeric keypad)
    VK_NUMPAD3 3 key (numeric keypad)
    VK_NUMPAD4 4 key (numeric keypad)
    VK_NUMPAD5 5 key (numeric keypad)
    VK_NUMPAD6 6 key (numeric keypad)
    VK_NUMPAD7 7 key (numeric keypad)
    VK_NUMPAD8 8 key (numeric keypad)
    VK_NUMPAD9 9 key (numeric keypad)
    }
    function TFloatEdit.DoKeyPress(var Message: TWMKey): Boolean;
    begin
     Result:=false;
     Message.Result:=1;
     if not(Char(Message.CharCode) in ['0'..'9','.'])and not (Message.CharCode in [VK_BACK]) then
    // if  (Message.CharCode<$30)or(Message.CharCode >$39)or (Char(Message.CharCode)<>'.') then
      begin
         Message.Result:=0;
         Result:=true;
      end;
    end;
    procedure TFloatEdit.WMChar(var Message:TWMKey);
    begin
     if not DoKeyPress(Message) then inherited;
    end;procedure TFloatEdit.CreateParams(var Params: TCreateParams);
    const
      Alignments: array[Boolean, TAlignment] of DWORD =
        ((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));begin
      inherited CreateParams(Params);
      with Params do
      begin
        Style := Style  or Alignments[UseRightToLeftAlignment, FTextAlign];
      end;
    end;
    procedure TFloatEdit.SetTextAlign(Value:TAlignment);
    begin
      FTextAlign:=Value;
      RecreateWnd;
    end;
    constructor TFloatEdit.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);end;
    procedure Register;
    begin
     RegisterComponents('abc',[TFloatEdit]);
    end;end.
      

  13.   

    上面是一个小小的例子(我不是来臭屁的,只是大家讨论),
    几个特别的地方:
    procedure TFloatEdit.CreateParams(var Params: TCreateParams);
    const
      Alignments: array[Boolean, TAlignment] of DWORD =
        ((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));begin
      inherited CreateParams(Params);
      with Params do
      begin
        Style := Style  or Alignments[UseRightToLeftAlignment, FTextAlign];
      end;
    end;
    上面这个过程是用来下定义控件风格的,其实在上面代码上可以不需要重载这个过程,
    我只是为了好看而已!
    procedure TFloatEdit.SetTextAlign(Value:TAlignment);
    begin
      FTextAlign:=Value;
      RecreateWnd;
    end;
    上面这个过程改变控件的显示风格,然后重建控件句柄,这是因为DELPHI的VCL的机制(也可以使用API SetClassLong来设置)在改变风格时可以使用ReCreateWnd方法来重建控件句柄,以使用控件的新风格生效!注意这是DELPHI的机制!
    function TFloatEdit.DoKeyPress(var Message: TWMKey): Boolean;
    begin
     Result:=false;
     Message.Result:=1;
     if not(Char(Message.CharCode) in ['0'..'9','.'])and not (Message.CharCode in [VK_BACK]) then
    // if  (Message.CharCode<$30)or(Message.CharCode >$39)or (Char(Message.CharCode)<>'.') then
      begin
         Message.Result:=0;
         Result:=true;//函数返回值,别和上面的Message.Result混了
      end;
    end;
    上面这个过程说明的问题是:
    当消息(TMessage对象的返回值(Result)域为0时表示该消息已经被处理,也就是对后面的过程说:你们都不用处理这条消息了,我已经做了该做了(对于上面的过程说,就是,如果是BACKSAPCE,数字和小数点我就留下用,其它的我不要,Result返回0)
    我的代码可能不是最简单的,希望大家指点!
      

  14.   

    // if  (Message.CharCode<$30)or(Message.CharCode >$39)or (Char(Message.CharCode)<>'.') then这一句不要
      

  15.   

    谢谢Cstarter(AnQiu001)
     你这个控件是为了只输入数值吧.
    欢迎各位继续踊跃参加,多劳多得,分数多多,大家不要客气呀
    国庆到了,大家快乐
      

  16.   

    windyhero(西门吹雪) 
    是为了数值,本来是想做个浮点数输入框的