关与TIMAGE控件重写的问题..在线等待!!! ( 积分: 100 )

  • 主题发起人 主题发起人 babyvs
  • 开始时间 开始时间
B

babyvs

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟做了一个控件继承TIMAGE.功能很简单,只加了4个属性,类型和pictur 一样.想要的功能也和他一样。要能在编辑状态加载图片.也就是运行前.并能把图片保存在程序中.

但是在我选择图片加载的时候就饱错了.读地址错误 in module 'rtl70.bpl' 估计是对象未创建.但是TIMAGE的PICTURE也在CREATE中创建的。在编辑状态也是NIL.所以我就郁闷了.

如果在FROM的CREATE中加图片则可以运行。但是不是我要的效果.(=没做.)
 
小弟做了一个控件继承TIMAGE.功能很简单,只加了4个属性,类型和pictur 一样.想要的功能也和他一样。要能在编辑状态加载图片.也就是运行前.并能把图片保存在程序中.

但是在我选择图片加载的时候就饱错了.读地址错误 in module 'rtl70.bpl' 估计是对象未创建.但是TIMAGE的PICTURE也在CREATE中创建的。在编辑状态也是NIL.所以我就郁闷了.

如果在FROM的CREATE中加图片则可以运行。但是不是我要的效果.(=没做.)
 
小弟急!!!.那位大哥来帮帮忙啊!!!
 
跟这个一样的就可以了啊:
procedure TImage.SetPicture(Value: TPicture);
begin
FPicture.Assign(Value);
end;

不然你把代码贴出来看看!
 
终于有人回了.先谢了.
-------
unit luwei;

interface

uses
SysUtils, Classes, Controls, ExtCtrls,Windows,Messages,Graphics;

type
Tluwei = class(TImage)
private
_DefImage :TPicture;
_EnterImage : TPicture;
_DownImage : TPicture;
_UnEableImage :TPicture;
procedure SetPicture(Value: TPicture);

procedure WM_MouseEnter(var message : TMessage);message CM_MOUSEENTER;
procedure WM_MouseLeave(var message : TMessage);message CM_MOUSEleave;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure Click; override;
{ Private declarations }
protected
procedure SetUnEnableImage;
procedure SetEnableImage;
procedure SetDisAble(value : boolean);virtual;
procedure SetEnAble(value : boolean);virtual;
{ Protected declarations }
public
{ Public declarations }
Disable : Boolean;
Enable : Boolean;
Down : Boolean;
Up : Boolean;
constructor Create(AOwner: TComponent); override;
published
property DefaultImage : TPicture read _DefImage Write _DefImage;
property EnterImage : TPicture read _EnterImage Write _EnterImage;
property DownImage : TPicture read _DownImage Write _DownImage;
property UnEnableImage : TPicture read _UnEableImage Write _UnEableImage;
property PEnable : Boolean read Enable write SetEnAble;
property PDisable : Boolean read Disable write SetDisAble default False;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Standard', [Tluwei]);
end;

{ Tluwei }



procedure Tluwei.Click;
begin
if Not Disable then Exit;
inherited;
end;

constructor Tluwei.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
_DefImage := TPicture.Create;
_DefImage.OnProgress := Progress;
_DownImage := TPicture.Create;
_DownImage.OnProgress := Progress;
_UnEableImage := TPicture.Create;
_UnEableImage.OnProgress := Progress;
_EnterImage := TPicture.Create;
_EnterImage.OnProgress := Progress;
Height := 24;
Width := 64;

Up := True;
Down := False;
Disable := True;
Enable := True;
end;

procedure Tluwei.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if Not Disable then Exit;
if PEnable then
begin
SetPicture(_DownImage);
Down := not Down;
Up := False;
end;
inherited;
end;

procedure Tluwei.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if Not Disable then Exit;
if PEnable then
begin
if Down then
begin
SetPicture(_DefImage);
Down := Not Down;
Up := True;
end;
end;
inherited;
end;

procedure Tluwei.SetDisAble(value: boolean);
begin
Disable := Value;

if Value then
self.SetEnableImage
else
self.SetUnEnableImage;
end;

procedure Tluwei.SetEnAble(value: boolean);
begin
if Not Disable then Exit;
if Value then
self.SetEnableImage
else
self.SetUnEnableImage;
end;

procedure Tluwei.SetEnableImage;
begin
self.SetPicture(_DefImage);
Enable := True;
end;

procedure Tluwei.SetPicture(Value: TPicture);
begin
// self.Picture.LoadFromFile(Value);

self.Picture.Assign(Value);
end;


procedure Tluwei.SetUnEnableImage;
begin
self.SetPicture(_UnEableImage);
Enable := False;
end;

procedure Tluwei.WM_MouseEnter(var message: TMessage);
begin
if Not Disable then Exit;

if PEnable and (Not Down) then
begin
SetPicture(_EnterImage);
end;

end;

procedure Tluwei.WM_MouseLeave(var message: TMessage);
begin
if Not Disable then Exit;

if PEnable then
begin
self.SetEnableImage;
// SetPicture(_DefImage);
end;
end;


end.


我是你这样写的,不行!!!
 
1 自己新加的三个PICTURE要在destructor Destroy; override;中FREE
2 SetPicture(Value: TPicture);函数这里不要用了,那是给原来TIMAGE的PICTURE用的,着个函数只是实现在设计期打开一个图片文件并把图片付值给指定的PICTURE,每个PICTURE都要有自己的SETPICTURE函数.
可以再写三个函数,举个例子
property DownImage : TPicture read _DownImage Write SetPictureDown;
procedure Tluwei.SetPictureDown(Value: TPicture);
begin
_DownImage.Assign(Value);
end;
最后在鼠标事件中例如
procedure Tluwei.WM_MouseLeave(var message: TMessage);
begin
FPicture := _DownImage;
//或 FPicture.BITMAP := _DownImage.BITMAP;
//传递图片的位图给默认的PICTURE属性,
//如果图片不能即时刷新可以调用一下PAINT
Paint;
end;
即可
 
非常感谢!!!.搞定了..感动!!!
 
后退
顶部