需要解决的是程序中有中文说明的那部分,有关前续的内容请参考
http://expert.csdn.net/Expert/topic/1724/1724872.xml?temp=.8736078
出300分绝不食言。unit DBListCombo;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,buttons,grids;type
  {TDBListCombo}
  TDBListComboStyle = (csDropDown, csDropDownList);  TDBListCombo = class(TCustomEdit)
  private
    { Private declarations }
    FValue:string;
    FButton:TSpeedButton;
    FGrid:TStringGrid;
    FStyle: TDBListComboStyle;
    FDropDownCount: integer;
    FDropDownWidth: integer;
    FTitleOffset: Integer;
    FBtnControl : TWinControl;
    function GetValue:string;
    procedure SetValue(Index:string);
//    procedure SetReadOnly(Value: Boolean);
    procedure SetStyle(Value: TDBListComboStyle);  protected
    { Protected declarations }
  public
    { Public declarations }    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure DropDown; dynamic;
    procedure CloseUp; dynamic;  published
    { Published declarations }
    property Text;
    property Height;
    property Width;
    property Value:string read GetValue write SetValue;
    property DropDownCount: Integer read FDropDownCount write FDropDownCount default 8;
    property DropDownWidth: Integer read FDropDownWidth write FDropDownWidth default 0;
    property Style: TDBListComboStyle read FStyle write SetStyle default csDropDown;  end;{ TPopupGrid }  TPopupGrid = class(TStringGrid)  private
    procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure CreateWnd; override;
  public
    property RowCount;
    constructor Create(AOwner: TComponent); override;
  end;  { TComboButton }  TComboButton = class(TSpeedButton)
  protected
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
end;procedure Register;implementationprocedure Register;
begin
  RegisterComponents('Data Controls', [TDBListCombo]);
end;constructor TDBListCombo.Create(AOwner: TComponent);
begin
  inherited;
  FBtnControl := TWinControl.Create(Self);
  FBtnControl.Width := 17;
  FBtnControl.Height := 17;
  FBtnControl.Top := 1 ;
  FBtnControl.Left := Width-18 ;{我想在此取得组件的WIDTH值,但得到的总是默认的121,不管我将组件的宽度设置为多少都如此。}
  FBtnControl.Visible := True;
  FBtnControl.Parent := Self;
  FButton := TComboButton.Create(self);
  FButton.Parent := FBtnControl;
  FButton.Visible := True ;
  FButton.SetBounds(0, 0, FBtnControl.Width, FBtnControl.Height);
  FButton.Glyph.Handle := LoadBitmap(0, PChar(32738));
  FGrid := TPopupGrid.Create(Self);
  FGrid.Parent := Self;
  FGrid.Visible := False; {我已经在这里将Visible设置为False,但为何设计时Fgrid仍可见,但运行时正常。}
//  FGrid.OnClick := GridClick;
  FGrid.Width := Width;
  FGrid.DefaultRowHeight := 21;
  FTitleOffset:=0;
//  FDropDownCount := 8;
end;destructor TDBListCombo.Destroy;
begin  inherited;end;function TDBListCombo.GetValue:string;
begin
 Result := FValue;
end;procedure TDBListCombo.SetValue(Index:string);
begin
 FValue := index;
end;procedure TDBListCombo.DropDown;
var
  ItemCount: Integer;
  P: TPoint;
  Y: Integer;
  GridWidth, GridHeight, BorderWidth: Integer;
  SysBorderWidth, SysBorderHeight: Integer;
begin  if not FGrid.Visible and (Width > 20) then
  begin
//    if Assigned(FOnDropDown) then FOnDropDown(Self);
    ItemCount := DropDownCount;
    if ItemCount = 0 then ItemCount := 1;
    SysBorderWidth := GetSystemMetrics(SM_CXBORDER);
    SysBorderHeight := GetSystemMetrics(SM_CYBORDER);
    P := ClientOrigin;
    if NewStyleControls then
    begin
      Dec(P.X, 2 * SysBorderWidth);
      Dec(P.Y, SysBorderHeight);
    end;
    BorderWidth := 1;
    GridHeight := (FGrid.DefaultRowHeight + BorderWidth) * ItemCount + 2;
    FGrid.Height := GridHeight;
    if ItemCount > FGrid.RowCount then
    begin
      ItemCount := FGrid.RowCount;
      GridHeight := (FGrid.DefaultRowHeight + BorderWidth) * ItemCount  + 4;
    end;
    if NewStyleControls then
      Y := P.Y + ClientHeight + 3 * SysBorderHeight else
      Y := P.Y + Height - 1;
    if (Y + GridHeight) > Screen.Height then
    begin
      Y := P.Y - GridHeight + 1;
      if Y < 0 then
      begin
        if NewStyleControls then
          Y := P.Y + ClientHeight + 3 * SysBorderHeight else
          Y := P.Y + Height - 1;
      end;
    end;
    GridWidth := DropDownWidth;
    if GridWidth = 0 then
    begin
      if NewStyleControls then
        GridWidth := Width + 2 * SysBorderWidth else
        GridWidth := Width - 4;
    end;
    if NewStyleControls then
      SetWindowPos(FGrid.Handle, 0, P.X, Y, GridWidth, GridHeight, SWP_NOACTIVATE) else
      SetWindowPos (FGrid.Handle, 0, P.X + Width - GridWidth, Y, GridWidth, GridHeight, SWP_NOACTIVATE);
    FGrid.Visible := True;
    Windows.SetFocus(Handle);
  end;
end;procedure TDBListCombo.SetStyle(Value: TDBListComboStyle);
begin
  if FStyle <> Value then
    FStyle := Value;
end;
procedure TDBListCombo.CloseUp;
begin
  FGrid.Visible := False;
end;procedure MouseDragToGrid(Ctrl: TControl; Grid: TPopupGrid; X, Y: Integer);
var
  pt, clientPt: TPoint;
begin
  if Grid.Visible then
  begin
    pt.X := X;
    pt.Y := Y;
    pt := Ctrl.ClientToScreen (pt);
    clientPt := Grid.ClientOrigin;
    if (pt.X >= clientPt.X) and (pt.Y >= clientPt.Y) and
       (pt.X <= clientPt.X + Grid.ClientWidth) and
       (pt.Y <= clientPt.Y + Grid.ClientHeight) then
    begin
      Ctrl.Perform(WM_LBUTTONUP, 0, MakeLong (X, Y));
      pt := Grid.ScreenToClient(pt);
      Grid.Perform(WM_LBUTTONDOWN, 0, MakeLong (pt.x, pt.y));
    end;
  end;
end;
procedure Click(Sender: TObject);
begin
  showmessage('Create an Object.');
end;{TPopupGrid}constructor TPopupGrid.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  TabStop := False;
  Options:=Options - [goHorzLine];
  Options:=Options + [goRowSelect];
  ScrollBars:=ssVertical;
  ColCount:=3;
  FixedCols:=0;
  FixedRows:=1;end;procedure TPopupGrid.CMHintShow(var Message: TMessage);
begin
  Message.Result := 1;
end;procedure TPopupGrid.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WindowClass.Style := CS_SAVEBITS;
end;procedure TPopupGrid.CreateWnd;
begin
  inherited CreateWnd;
  if not (csDesigning in ComponentState) then
    Windows.SetParent(Handle, 0);
  CallWindowProc(DefWndProc, Handle, WM_SETFOCUS, 0, 0);
//  FCombo.DataChange(Self);
end;{ TComboButton }constructor TComboButton.Create(AOwner: TComponent);
begin
  inherited;
end;procedure TComboButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
begin
{  with TDBListCombo (Parent.Parent) do
    if not FGrid.Visible then
      if (Handle <> GetFocus) and CanFocus then
      begin
        SetFocus;
        if GetFocus <> Handle then Exit;
      end;
  inherited MouseDown (Button, Shift, X, Y);
  with TDBListCombo (Parent.Parent) do
    if FGrid.Visible then CloseUp
    else DropDown;
}
with TDBListCombo (Parent.Parent) do
DropDown;
end;end.

解决方案 »

  1.   

    控件即使Visble为FALSE,设计时也是可见的.你想改变Width,不能通过default,只能在构造函数里指定.
      

  2.   

    但由以下代码可以看到,我并未为WIDTH指定默认值啊。 published
        { Published declarations }
        property Text;
        property Height;
        property Width;
        property Value:string read GetValue write SetValue;
        property DropDownCount: Integer read FDropDownCount write FDropDownCount default 8;
        property DropDownWidth: Integer read FDropDownWidth write FDropDownWidth default 0;
        property Style: TDBListComboStyle read FStyle write SetStyle default csDropDown;
      

  3.   

    To :hkbarton(我是好人) 
        先前那帖你帖的代码我测试了好象也不能通过啊。
      

  4.   

    谢谢各位朋友的帮忙,问题已经解决。
    最终通过扑获TWMSize消息解决该问题。
      

  5.   

    你以下是先前的贴的内容,我在前面声明作了修改,你再试试//TMyOncreate = procedure(sender: TObject);
    TMyOncreate = procedure(sender: TObject) of object;//modified
    private
      FMyOncreate:TMyOncreate;
    published
      property MyOncreate:TMyOncreate read FMyOncreate write FMyoncreate;procedure Tmyclass.Oncreate(sender: Tobjece);
    begin
      If assigned(FMyoncreate) then FMyoncreate(sender);
    end;