constructor TComboButton.Create(AOwner: TComponent);
  var
    mButtonsWidth:integer;
begin
  inherited;
  with TDBListCombo (Parent.Parent) do
     mButtonsWidth := Width;
  showmessage(inttostr(mButtonsWidth)); //****************
//  Left := mButtonsWidth ;
end;以上代码运行的时候出现如下错误:
Exception EAccessViolation in module Project1.exe at 00086F80.
Access violation at address 0048F80 in module 'Project1.exe'.Read of address 00000024.
错误行在带星号的那行,如果注释该行则没有错误,请问这是什么原因呢?

解决方案 »

  1.   

    帮你UP!帮你UP!帮你UP!帮你UP!帮你UP!帮你UP!帮你UP!
      

  2.   

    是不是未Uses Dialogs or QDialogs 的Unit
      

  3.   

    应该不会是的,因为如果把代码改为如下后也有同样的问题。看来似乎是只要读TCOMBOBUTTON的WIDTH的值就会出问题。constructor TComboButton.Create(AOwner: TComponent);
      var
        mButtonsWidth:integer;
    begin
      inherited;
      with TDBListCombo (Parent.Parent) do
         mButtonsWidth := Width;
    //  showmessage(inttostr(mButtonsWidth)); //****************
      Left := mButtonsWidth ;
    end;
      

  4.   

    constructor TComboButton.Create(AOwner: TComponent);
      var
        mButtonsWidth:integer;
    begin
      inherited;
      with TDBListCombo (Parent.Parent) do
    begin
         mButtonsWidth := Width;
    //  showmessage(inttostr(mButtonsWidth)); //****************
      Left := mButtonsWidth ;
    end;
    end;
      

  5.   

    Parent.Parent??  确认这个不是空值?
      

  6.   

    constructor TDBListCombo.Create(AOwner: TComponent);
    begin
      inherited;
      FBtnControl := TWinControl.Create(Self);
      FBtnControl.Width := 17;
      FBtnControl.Height := 17;
      FBtnControl.Visible := True;
      FBtnControl.Parent := Self;
      FButton := TComboButton.Create(self);
      FButton.Parent := FBtnControl;
      FButton.Top := 1 ;
      FButton.Left := 1 ;
      FBtnControl.Width := 17;
      FBtnControl.Height := 17;
      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;
      FGrid.Width := Width;
      Height := 25;
      FTitleOffset:=0;
    //  FDropDownCount := 8;end;以上的代码是对组件的定义,
    TComboButton的parent.parent 是指TDBListCombo还是FBtnControl?我自己都糊涂了。
      

  7.   

    我的本意是想取得TDBListCombo的Width值,但在constructor TDBListCombo.Create(AOwner: TComponent)中取得的是默认的值(总是121),如果没有使用默认值取得的还会是默认值。可否通过其他的方法取得呢?
      

  8.   

    以下这段代码运行的时候却没有任何问题。
    procedure TComboButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer);
    begin
    with TDBListCombo (Parent.Parent) do
    DropDown;
    end;
      

  9.   

    TDBListCombo是由TCustomEdit继承而来的。
      

  10.   

    在Create的时候,Parent尚未赋值.
      

  11.   

    非常赞同 INeedCa(缺钙) 的看法,如果是这样那我该将相应的代码加到哪个方法中好。
    可惜TCustomEdit类好象没有resize事件啊?
      

  12.   

    我曾尝试在show方法中获取width的值,采用如下语句:
    procedure show;override;
    但得到错误提示:
    Cannot override a static method
    这该如何解决呢?用show方法能否解决问题?等待ing,等待ing,等待ing,等待ing,等待ing,等待ing,
    等待ing,等待ing,等待ing,等待ing,等待ing,等待ing,
    等待ing,等待ing,等待ing,等待ing,等待ing,等待ing,
    等待ing,等待ing,等待ing,等待ing,等待ing,等待ing,
      

  13.   

    不要在构造函数里取,可以在OnCreate,OnPaint,OnActivate之类事件中实现.一般来说,如果该控件有OnCreate事件的话,就在它里面加代码就好.
      

  14.   

    procedure SetParent(AParent: TWinControl); override;