自定義元件出現 AV 錯誤 |
尚未結案
|
agerchen
一般會員 發表:8 回覆:6 積分:2 註冊:2006-12-08 發送簡訊給我 |
我自行寫了一個簡單的元件,但是運作時會出現 Access Violation 的錯誤。
請大哥們幫忙看一下,我那裏寫錯了。 [code delphi] unit syimage; interface uses {$IFDEF WIN32} Windows, {ThdTimer,} {$ELSE} WinTypes, WinProcs, {$ENDIF} Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, Vcl.Imaging.GIFImg{, GR32}; type TsyImage = class(TImage) private FLoading: Boolean; FNoimg: Boolean; FSaveStretch: Boolean; FLocalfile: string; procedure SetLoading(value: boolean); procedure SetNoImg(value: boolean); protected FOnChange: TNotifyEvent; FOldInChange: TNotifyEvent; procedure DoOnPictureChange(Sender: TObject); procedure Paint; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property OnChange: TNotifyEvent read FOnChange write FOnChange; property Loading: boolean read FLoading write SetLoading default false; property NoImg: boolean read FNoimg write SetNoImg; property Localfile: string read FLocalfile write FLocalfile; procedure ClearGraphic; end; procedure Register; implementation {$R syimage.RES} //const // MaxDelayTime = 10000; // MinDelayTime = 50; procedure Register; begin RegisterComponents('Ager', [TsyImage]); end; { TsyImage } procedure TsyImage.SetLoading(value: boolean); var ResSt : TResourceStream; gif: TGIFImage; begin if value <> FLoading then //<-- 這裏會出現錯誤 (FLoading 找不到) FLoading:=value; if FLoading then begin SetNoImg(false); FSaveStretch:=self.Stretch; self.Stretch:=false; gif:=TGIFImage.Create; ResSt:=TResourceStream.Create(HInstance, 'LOAD6', 'RT_RCData'); try ResSt.Position:=0; gif.LoadFromStream(ResSt); self.Picture.Graphic:=gif; finally ResSt.Free; gif.Free; end; (self.Picture.Graphic as TGIFImage).Animate:=true; end else begin ClearGraphic(); self.Stretch:=FSaveStretch; end; end; procedure TsyImage.SetNoImg(value: boolean); var ResSt : TResourceStream; gif: TGIFImage; begin if value <> FNoimg then FNoimg:=value; if FNoimg then begin SetLoading(false); FSaveStretch:=self.Stretch; self.Stretch:=false; gif:=TGIFImage.Create; ResSt:=TResourceStream.Create(HInstance, 'NOIMG', 'RT_RCData'); try ResSt.Position:=0; gif.LoadFromStream(ResSt); self.Picture.Graphic:=gif; finally ResSt.Free; gif.Free; end; end else begin ClearGraphic(); self.Stretch:=FSaveStretch; end; end; constructor TsyImage.Create(AOwner: TComponent); begin inherited Create(AOwner); end; destructor TsyImage.Destroy; begin inherited Destroy; end; procedure TsyImage.DoOnPictureChange(Sender: TObject); begin if Assigned(FOldInChange) then FOldInChange(Self); if Assigned(FOnChange) then FOnChange(Self); end; procedure TsyImage.Paint; begin inherited Paint; { canvas.brush.style := bsClear; if (csDesigning in ComponentState) then begin with canvas do begin pen.style := psDot; pen.width := 1; pen.color := clBlack; Rectangle(0, 0, Width, Height); end; end; } // GetCurrentBitmap; end; procedure TsyImage.ClearGraphic; //var // tmp: Tbitmap; begin { if self.Picture.Bitmap.Empty then begin tmp:=Tbitmap.Create; try tmp.Width:=self.width; tmp.Height:=self.height; tmp.Canvas.Brush.Color := clWhite; tmp.Canvas.FillRect(Rect(0, 0, tmp.width, tmp.height)); self.Picture.Bitmap:=tmp; finally tmp.Free; end; end else begin self.Picture.Bitmap.Canvas.Brush.Color:=clWhite; self.Picture.Bitmap.Canvas.FillRect(Rect(0, 0, width, height)); end; self.Repaint; } { tmp:=Tbitmap.Create; try tmp.Width:=self.width; tmp.Height:=self.height; tmp.Canvas.Brush.Color := clWhite; tmp.Canvas.FillRect(Rect(0, 0, tmp.width, tmp.height)); self.Picture.Bitmap:=tmp; self.Repaint; finally tmp.Free; end; } end; end. [/code] |
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |