控件中{$ *.res}报找不到,已定义TBitmap变量但led:=tbitmap.create和canvas.copyrect(d,led.canvas,s

  • 主题发起人 主题发起人 hji
  • 开始时间 开始时间
H

hji

Unregistered / Unconfirmed
GUEST, unregistred user!
控件中{$ *.res}报找不到,已定义TBitmap变量但led:=tbitmap.create和canvas.copyrect(d,led.canvas,s)报错。(50分)<br />
 
请详细一点!
 
你是想自己做控件?
 
你看到与你unit同名的 res 文件吗
 
控件源码如下,请帮忙查对,报错的地方用*号标出,多谢!
unit ledcntrl;

interface

uses
SysUtils,WinTypes,WinProcs,Windows, Messages, Classes, Graphics,
Controls, Forms, Dialogs;
type
TLDisp = class(TGraphicControl)
private
{ Private declarations 用来存储新增加的三个属性值}
FDisplay:string;
FEnabled:Boolean;
FDisplayType:integer;
protected
{ Protected declarations }
procedure Paint;override;
procedure SetDisplay(s:string);
procedure SetEnabled1(e:boolean);
procedure SetDisplayType(t:integer);
public
{ Public declarations }
constructor Create(anowner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property Display:string read FDisplay write SetDisplay;
property Enabled:Boolean read FEnabled write SetEnabled;
property DisplayType:integer read FDisplayType write SetDisplayType;
end;

var
LEDs,LCDs:TBitmap;***************************
const
cnt:integer=0;
procedure Register;
procedure GetLed(dig:char;state:Boolean;var r:Trect);

implementation

{$R c:/LEDCNTRL.RES}*******************是不是要掉入一个控件图标

//构造函数
constructor TLDisp.Create(Anowner:TComponent);
begin
inherited Create(Anowner);
if cnt=0 then //如果还没有实例创建,生成两个位图
begin
LEDs:=TBitmap.create;
lcds:=tbitmap.create;
leds.loadfromfile('C:/Borland/Delphi5/test3/type0.bmp');
lcds.loadfromfile('C:/Borland/Delphi5/test3/type1.bmp');
end;
inc(cnt);
end;

//析构函数
destructor TLDisp.Destroy;
begin
dec(cnt);
if cnt=0 then
begin
LEDs.Free;
LCDs.Free;
end;
inherited Destroy;
end;
//设置enabled属性
procedure TLDisp.SetEnabled1(e:Boolean);
begin
if e&lt;&gt;FEnabled then
begin
FEnabled:=e;
Paint;
end;
end;
//设置display属性
procedure TLDisp.SetDisplay(s:string);
begin
if s&lt;&gt;FDisplay then
begin
FDisplay:=s;
Paint;
end;
end;
// 设置displaytype属性
procedure TLDisp.SetDisplayType(t:integer);
begin
if t&lt;&gt;FDisplayType then
begin
FDisplayType:=t;
Paint;
end;
end;
//重新显示控件上的数字
procedure TLDisp.Paint;
var
lp:integer;
s,d:Trect;
begin
d.left:=0;
d.top:=0;
d.bottom:=24;
for lp:=1 to length (Display) do
begin
Getled(Display[lp],FEnabled,s);
d.right:=(s.right-s.left)+d.left;
if FDisplayType=0 then
canvas.copyrect(d,LEDs.canvas,s)*************************
else
canvas.copyrect(d,LEDs.canvas,s);
d.left:=d.right;
end;
end;

//下面是前述paint过程用到的得到源矩形块的getled过程

procedure GetLed(dig:char;state:boolean;var r:Trect);
begin
r.top:=0;
r.bottom:=24;
case state of
True:
case dig of
'0'..'9':
begin
r.left:=(integer(dig)-48)*14;
r.right:=r.left+14;
end;
'.':
begin
r.left:=155;
r.right:=160;
end;
else
r.left:=141;
r.right:=155;
end;
False:
if dig='.' then
begin
r.left:=161;
r.right:=16;
end;
else
begin
r.left:=141;
r.right:=155;
end;
end; {edn case}
end;
procedure Register;
begin
RegisterComponents('Samples', [TLDisp]);
end;

end.
 
{$R *.RES}
把LEDCNTRL.RES与LEDCNTRL.pas放在同一目录下
 
接受答案了.
 
后退
顶部