小弟愚見﹐因為你在編譯時沒有出錯﹐我想TPicture是個對象﹐而不是數據類型﹐你要以在TImage的構造過程中看到﹐創建TPicture對象實例的代碼﹐你有沒有寫啊﹖﹖﹖
當然析構中也有......一點猜測﹗

解决方案 »

  1.   

    在构造函数中明明白白的建立了对象,在析构函数中明明白白的释放了……55555555~~~~~~~
    看现象是在程序从DFM(当然已经编译进EXE中了)读取控件的属性值的时候找不到具有该名称的属性才发生的问题。而且令人无法理解的是:竟然连TAlignment这样的属性都会出问题……我还是把源代码贴出来吧,没什么东西,可以直接安装,设计时可以使用。共有两个文件:
    1、SMacGraphic.pas
    2、SMacButton.pasunit SMacGraphic;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Buttons;type
      TSMacBevelStyle=TBevelCut;
      TSMacBevelColorSet=record
        c3DFace,c3DHighLight,c3DShadow,c3DDkShadow,cSpace:TColor;
      end;var
      SMacC_3DFace,SMacC_3DHighLight,SMacC_3DShadow,SMacC_3DDkShadow,SMacC_Space,
      NormalTextColor,DeactiveTextColor,TextHighLightColor,DisabledTextColor:TColor;
      DefaultColorSet:TSMacBevelColorSet;procedure DrawBevel(Canvas:TCanvas;Rect:TRect;
      const Colors:TSMacBevelColorSet;BevelStyle:TSMacBevelStyle;Filled:Boolean);
    function ColorSet(c3DFace,c3DHighLight,
      c3DShadow,c3DDkShadow,cSpace:TColor):TSMacBevelColorSet;
    procedure DefaultBevel(Canvas:TCanvas;Rect:TRect;
      BevelStyle:TSMacBevelStyle;Filled:Boolean);implementationfunction ColorSet(c3DFace,c3DHighLight,
      c3DShadow,c3DDkShadow,cSpace:TColor):TSMacBevelColorSet;
    begin
      Result.c3DFace:=c3DFace;
      Result.c3DHighLight:=c3DHighLight;
      Result.c3DShadow:=c3DShadow;
      Result.c3DDkShadow:=c3DDkShadow;
      Result.cSpace:=cSpace;
    end;procedure DrawBevel(Canvas:TCanvas;Rect:TRect;
      const Colors:TSMacBevelColorSet;BevelStyle:TSMacBevelStyle;Filled:Boolean);
    var
      ColorH,ColorD:TColor;
    begin
      //Set Colors
      ColorH:=Colors.c3DHighLight;
      ColorD:=Colors.c3DShadow;
      case BevelStyle of
        bvNone:Exit;
        bvRaised:
        begin
          ColorH:=Colors.c3DHighLight;
          ColorD:=Colors.c3DShadow;
        end;
        bvLowered:
        begin
          ColorD:=Colors.c3DHighLight;
          ColorH:=Colors.c3DShadow;
        end;
        bvSpace:
        begin
          ColorH:=Colors.cSpace;
          ColorD:=Colors.cSpace;
        end;
      end;  //Draw Bevel
      with Canvas do
      begin
        if Filled then
        begin
          Brush.Style:=bsSolid;
          Brush.Color:=Colors.c3DFace;
          FillRect(Rect);
        end;
        Pen.Style:=psSolid;
        Pen.Width:=1;
        Pen.Color:=ColorH;
        MoveTo(Rect.Right-1,Rect.Top);
        LineTo(Rect.Left,Rect.Top);
        LineTo(Rect.Left,Rect.Bottom-1);
        Pen.Color:=ColorD;
        LineTo(Rect.Right-1,Rect.Bottom-1);
        LineTo(Rect.Right-1,Rect.Top);
      end;
    end;procedure DefaultBevel(Canvas:TCanvas;Rect:TRect;
      BevelStyle:TSMacBevelStyle;Filled:Boolean);
    begin
      DrawBevel(Canvas,Rect,DefaultColorSet,BevelStyle,Filled);
    end;initialization
      SMacC_3DFace:=clBtnFace;
      SMacC_3DHighLight:=clBtnHighLight;
      SMacC_3DShadow:=clBtnShadow;
      SMacC_3DDkShadow:=cl3DDkShadow;
      SMacC_Space:=clBtnShadow;
      DefaultColorSet:=ColorSet(SMacC_3DFace,SMacC_3DHighLight,
        SMacC_3DShadow,SMacC_3DDkShadow,SMacC_Space);
      NormalTextColor:=clWindowText;
      DeactiveTextColor:=clBtnShadow;
      TextHighLightColor:=clBtnHighLight;
      DisabledTextColor:=clBtnShadow;end.//-----------------------------------------------------------
    unit SMacButton;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Buttons, SMacGraphic, Math;type
      TSMacButtonState=(smbsNormal,//Normal State
        smbsDown,//When Button Down
        smbsPressed,//When Button Pressed
        smbsActive,//When Mouse_in etc.
        smbsDisabled);//Disabled  TSMacButton = class(TCustomControl)
      private
        { Private declarations }
        Buffer:TBitmap;
        FGlyph:TPicture;
        FState:TSMacButtonState;
        FTextAlignment:TAlignment;
        FLayOut:TButtonLayOut;
        FCaption:String;
        FDoRepaint:Boolean;
        FWordWrap:Boolean;
        FShadowColor:TColor;
        FShadowOffset:Integer;
        FMargin,FSpacing:Integer;
        FGlyphTransparent:Boolean;
        FDown:Boolean;    FOnMouseEnter:TNotifyEvent;
        FOnMouseLeave:TNotifyEvent;    procedure SetGlyph(Value:TPicture);
        function GetGlyphRect(ARect:TRect):TRect;
        function GetTextRect(ARect:TRect):TRect;
        procedure SetLayOut(Value:TButtonLayOut);
        procedure SetAlignment(Value:TAlignment);
        procedure SetCaption(Value:String);
        procedure SetShadowColor(Value:TColor);
        procedure SetWordWrap(Value:Boolean);
        procedure SetShadowOffset(Value:Integer);
        procedure SetMargin(Value:Integer);
        procedure SetSpacing(Value:Integer);
        procedure SetGlyphTransparent(Value:Boolean);
        function GetFont:TFont;
        procedure SetFont(Value:TFont);
      protected
        { Protected declarations }
        procedure Paint;override;
        procedure PaintToBuffer;
        procedure WMSize(var Msg:TMessage);message WM_SIZE;
        procedure CMMouseEnter(var Msg:TMessage);message CM_MOUSEENTER;
        procedure CMMouseLeave(var Msg:TMessage);message CM_MOUSELEAVE;
        procedure WMLButtonDown(var Msg:TMessage);message WM_LBUTTONDOWN;
        procedure WMLButtonUp(var Msg:TMessage);message WM_LBUTTONUP;
        procedure CMFontChanged(var Msg:TMessage);message CM_FONTCHANGED;
        procedure CMEnabledChanged(var Msg:TMessage);message CM_ENABLEDCHANGED;
        procedure WMEraseBkgnd(var Msg:TMessage);message WM_ERASEBKGND; 
      public
        { Public declarations }
        constructor Create(AOwner:TComponent);override;
        destructor Destory;
        procedure Refresh;
      published
        { Published declarations }
        property Glyph:TPicture read FGlyph write SetGlyph;
        property State:TSMacButtonState read FState;
        property TextAlignment:TAlignment read FTextAlignment write SetAlignment;
        property LayOut:TButtonLayOut read FLayOut write SetLayOut;
        property Caption:String read FCaption write SetCaption;
        property WordWrap:Boolean read FWordWrap write SetWordWrap;
        property ShadowColor:TColor read FShadowColor write SetShadowColor;
        property ShadowOffset:Integer read FShadowOffset write SetShadowOffset;
        property Margin:Integer read FMargin write SetMargin;
        property Spacing:Integer read FSpacing write SetSpacing;
        property GlyphTransparent:Boolean read FGlyphTransparent write SetGlyphTransparent;
        property Font:TFont read GetFont write SetFont;    property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
        property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;    property Hint;
        property Align;
        property Anchors;
        property OnMouseMove;
        property OnMouseDown;
        property OnMouseUp;
        property OnClick;
        property Enabled;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('SilentMac', [TSMacButton]);
    end;{ TSMacButton }procedure TSMacButton.CMEnabledChanged(var Msg: TMessage);
    begin
      inherited;
      if not Enabled then FState:=smbsDisabled
      else FState:=smbsNormal;
      Refresh;
    end;procedure TSMacButton.CMFontChanged(var Msg: TMessage);
    begin
      Refresh;
    end;procedure TSMacButton.CMMouseEnter(var Msg: TMessage);
    begin
      if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
    end;procedure TSMacButton.CMMouseLeave(var Msg: TMessage);
    begin
      if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
    end;constructor TSMacButton.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FGlyph:=TPicture.Create;
      Buffer:=TBitmap.Create;
      Width:=80;
      Height:=40;
      Buffer.Width:=80;
      Buffer.Height:=40;
      FTextAlignment:=taLeftJustify;
      FLayOut:=blGlyphLeft;
      FCaption:='Silent Mac Button';
      FDoRepaint:=True;
      FState:=smbsNormal;
      FWordWrap:=True;
      FShadowColor:=SMacC_3DShadow;
      FShadowOffset:=1;
      FMargin:=0;
      FSpacing:=2;
      FGlyphTransparent:=True;
      FDown:=False;
    end;destructor TSMacButton.Destory;
    begin
      FGlyph.Free;
      Buffer.Free;
      inherited;
    end;function TSMacButton.GetFont: TFont;
    begin
      Result:=Canvas.Font;
    end;function TSMacButton.GetGlyphRect(ARect:TRect): TRect;
    var
      l,t:Integer;
    begin
      Result:=ARect;
      if FGlyph=nil then Exit
      else
      begin
        case FLayOut of
          blGlyphLeft:
          begin
            l:=ARect.Left+FMargin;
            t:=ARect.Top+(ARect.Bottom-ARect.Top-FGlyph.Height) div 2;
            Result:=Rect(l,t,l+FGlyph.Width,t+FGlyph.Height);
          end;
          blGlyphRight:
          begin
            l:=ARect.Right-FMargin-FGlyph.Width;
            t:=ARect.Top+(ARect.Bottom-ARect.Top-FGlyph.Height) div 2;
            Result:=Rect(l,t,l+FGlyph.Width,t+FGlyph.Height);
          end;
          blGlyphTop:
          begin
            l:=ARect.Left+(ARect.Right-ARect.Left-FGlyph.Width) div 2;
            t:=ARect.Top+FMargin;
            Result:=Rect(l,t,l+FGlyph.Width,t+FGlyph.Height);
          end;
          blGlyphBottom:
          begin
            l:=ARect.Left+(ARect.Right-ARect.Left-FGlyph.Width) div 2;
            t:=ARect.Bottom-FMargin-FGlyph.Height;
            Result:=Rect(l,t,l+FGlyph.Width,t+FGlyph.Height);
          end;
        end;
      end;
    end;function TSMacButton.GetTextRect(ARect:TRect): TRect;
    var
      a,b:Integer;
    begin
      Result:=ARect;
      if FGlyph=nil then Exit
      else
      begin
        case FLayOut of
          blGlyphLeft:
          begin
            a:=ARect.Left+FMargin+FGlyph.Width+FSpacing;//Left
            b:=ARect.Top;//Top
            Result:=Rect(Min(ARect.Right,a),b,ARect.Right,ARect.Bottom);
          end;
          blGlyphRight:
          begin
            a:=ARect.Right-FMargin-FGlyph.Width-FSpacing;//Right
            b:=ARect.Top;//Top
            Result:=Rect(ARect.Left,b,Max(ARect.Left,a),ARect.Bottom);
          end;
          blGlyphTop:
          begin
            a:=ARect.Left;//Left
            b:=ARect.Top+FMargin+FGlyph.Height+FSpacing;//Top
            Result:=Rect(a,Min(b,ARect.Bottom),ARect.Right,ARect.Bottom);
          end;
          blGlyphBottom:
          begin
            a:=ARect.Left;//Left
            b:=ARect.Bottom-FMargin-FGlyph.Height-FSpacing;//Bottom
            Result:=Rect(a,ARect.Top,ARect.Right,Max(b,ARect.Top));
          end;
        end;
      end;
    end;procedure TSMacButton.Paint;
    begin
      inherited;
      //if Buffer=nil then Exit;
      if FDoRepaint then PaintToBuffer;
      BitBlt(Canvas.Handle,0,0,Width,Height,Buffer.Canvas.Handle,0,0,SRCCOPY);
      FDoRepaint:=False;
    end;procedure TSMacButton.PaintToBuffer;
    var
      Bevel:TSMacBevelStyle;
      ColorSet:TSMacBevelColorSet;
      TextColor:TColor;
      DrawShadow:Boolean;
      gRect,txtRect,Rect:TRect;
      TextStyle:UINT;
    const
      Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
      LayOuts: array[TButtonLayOut] of UINT = (DT_VCENTER, DT_VCENTER, DT_TOP, DT_BOTTOM);
      WordWraps: array[Boolean] of Word = (DT_SINGLELINE, DT_WORDBREAK);
    begin
      if Buffer=nil then Exit;  //Initialzation
      Buffer.Canvas.Font:=Canvas.Font;
      ColorSet:=DefaultColorSet;
      TextColor:=Buffer.Canvas.Font.Color;
      DrawShadow:=True;
      Buffer.Canvas.Brush.Style:=bsClear;
      Rect:=ClientRect;
      Bevel:=bvRaised;  //Set BorderStyle and TextColor
      case FState of
        smbsNormal://Normal State
        begin
          Bevel:=bvRaised;
          //TextColor:=NormalTextColor;
        end;
        smbsDown://When Button pressed
        begin
          Bevel:=bvLowered;
          //TextColor:=NormalTextColor;
        end;
        smbsPressed://When Mouse_in etc.
        begin
          Bevel:=bvSpace;
          //TextColor:=TextHighLightColor;
        end;
        smbsDisabled://Disabled
        begin
          Bevel:=bvRaised;
          TextColor:=DisabledTextColor;
          DrawShadow:=False;
        end;
      end;  //Set Text Style
      TextStyle := DT_EXPANDTABS or WordWraps[FWordWrap] or
        Alignments[FTextAlignment] or LayOuts[FLayOut];  //Draw To Buffer
      with Buffer.Canvas do
      begin
        Brush.Style:=bsSolid;
        Brush.Color:=SMacC_3DFace;
        FillRect(ClientRect);    //Draw Border
        Brush.Style:=bsClear;
        Pen.Color:=clBlack;
        RoundRect(ClientRect.Left,ClientRect.Top,
          ClientRect.Right,ClientRect.Bottom,2,2);
        InflateRect(Rect,-1,-1);
        DefaultBevel(Buffer.Canvas,Rect,Bevel,False);    //Get Elementposition
        InflateRect(Rect,-1,-1);
        gRect:=GetGlyphRect(Rect);
        txtRect:=GetTextRect(Rect);    //Draw Glyph
        if FGlyph.Graphic<>nil then
        begin
          FGlyph.Graphic.Transparent:=FGlyphTransparent;
          Draw(gRect.Left,gRect.Top,FGlyph.Graphic);
        end;    //Draw text
        if DrawShadow and Enabled then
        begin
          OffsetRect(txtRect,FShadowOffset,FShadowOffset);
          Buffer.Canvas.Font.Color:=FShadowColor;
          DrawText(Handle,PChar(FCaption),Length(FCaption),txtRect,TextStyle);
          OffsetRect(txtRect,-FShadowOffset,-FShadowOffset);
        end;
        if not Enabled then
        begin
          OffsetRect(txtRect,1,1);
          Buffer.Canvas.Font.Color:=SMacC_3DHighLight;
          DrawText(Handle,PChar(FCaption),Length(FCaption),txtRect,TextStyle);
          OffsetRect(txtRect,-1,-1);
        end;
        Buffer.Canvas.Font.Color:=TextColor;
        DrawText(Handle,PChar(FCaption),Length(FCaption),txtRect,TextStyle);
      end;
    end;procedure TSMacButton.Refresh;
    begin
      FDoRepaint:=True;
      Invalidate;
    end;procedure TSMacButton.SetAlignment(Value: TAlignment);
    begin
      FTextAlignment:=Value;
      Refresh;
    end;procedure TSMacButton.SetCaption(Value: String);
    begin
      FCaption:=Value;
      Refresh;
    end;procedure TSMacButton.SetFont(Value: TFont);
    begin
      Canvas.Font:=Value;
      Buffer.Canvas.Font:=Value;
      Refresh;
    end;procedure TSMacButton.SetGlyph(Value: TPicture);
    begin
      FGlyph.Assign(Value);
      Refresh;
    end;procedure TSMacButton.SetGlyphTransparent(Value: Boolean);
    begin
      FGlyphTransparent:=Value;
      Refresh;
    end;procedure TSMacButton.SetLayOut(Value: TButtonLayOut);
    begin
      FLayOut:=Value;
      Refresh;
    end;procedure TSMacButton.SetMargin(Value: Integer);
    begin
      FMargin:=Value;
      Refresh;
    end;procedure TSMacButton.SetShadowColor(Value: TColor);
    begin
      FShadowColor:=Value;
      Refresh;
    end;procedure TSMacButton.SetShadowOffset(Value: Integer);
    begin
      FShadowOffset:=Value;
      Refresh;
    end;procedure TSMacButton.SetSpacing(Value: Integer);
    begin
      FSpacing:=Value;
      Refresh;
    end;procedure TSMacButton.SetWordWrap(Value: Boolean);
    begin
      FWordWrap:=Value;
      Refresh;
    end;procedure TSMacButton.WMEraseBkgnd(var Msg: TMessage);
    begin
      
    end;procedure TSMacButton.WMLButtonDown(var Msg: TMessage);
    begin
      inherited;
      FDown:=True;
      FState:=smbsPressed;
      Refresh;
    end;procedure TSMacButton.WMLButtonUp(var Msg: TMessage);
    begin
      inherited;
      FDown:=False;
      FState:=smbsNormal;
      Refresh;
    end;procedure TSMacButton.WMSize(var Msg: TMessage);
    begin
      if Buffer=nil then Exit;
      Buffer.Width:=Width;
      Buffer.Height:=Height;
      Refresh;
    end;end.
      

  2.   

    加上一点说明:
    1、后来我尝试了一下在中文Win98下,完全正常。
    2、我原来使用的是德文Win2000。但是如果在一个应用程序的Project Manager中加入SMacButton单元(不是uses)的话就没有出现上述的找不到属性的问题。
    3、现在问题是:这个Bug是我的Bug还是Delphi的Bug还是德文Windows2000的Bug?怎样解决?我可不想每作一个工程就手动把SMacButton单元加进去。