全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:244
推到 Plurk!
推到 Facebook!

自定義元件出現 AV 錯誤

尚未結案
agerchen
一般會員


發表:7
回覆:5
積分:2
註冊:2006-12-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2016-10-25 02:43:21 IP:114.35.xxx.xxx 未訂閱
我自行寫了一個簡單的元件,但是運作時會出現 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
F 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(F 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.
版主


發表:571
回覆:3880
積分:3666
註冊:2006-10-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2016-10-25 08:32:10 IP:118.160.xxx.xxx 未訂閱
你應該把錯誤message貼上來, 要不然誰知道那 "落落長" 的 code 那邊有問題?
系統時間:2017-10-20 9:37:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!