组件问题!!急!

vargent77 2003-09-30 03:00:11
这里是我写的程序,是一个由label和bitbtn组成的组件,上半是bitbtn,下半是label!
unit Mywin5;

interface

uses
Windows,Messages,Graphics,Forms,Dialogs,StdCtrls,Buttons,SysUtils, Classes, Controls,Variants;

type
TMywin4 = class(TWinControl)
private
{ Private declarations }
FBitbtn:TBitBtn;
FLabel:TLabel;
//FCanvas: TCanvas;
FGlyph: TBitmap;

//procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
protected
{ Protected declarations }
procedure WMSize(var Message:TWMSize);message WM_SIZE;
procedure SetText(Value:String);
function GetText:String;
procedure SetFont(Value:TFont);
function GetFont:TFont;
procedure SetCaption(Value:String);
function GetCaption:String;
procedure SetOnButtonClick(Value:TNotifyEvent);
function GetOnButtonClick:TNotifyEvent;
procedure SetGlyph(Value: TBitmap);
function GetGlyph: TBitmap;

public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;

published
{ Published declarations }
property Text:String read GetText write SetText;
property Font:TFont read GetFont write SetFont;
property Caption:String read GetCaption write SetCaption;
property OnButtonClick:TNotifyEvent read GetOnButtonClick write SetOnButtonClick;

property Enabled;
property Glyph: TBitmap read GetGlyph write SetGlyph;

end;

procedure Register;

implementation





procedure TMywin4.WMSize(var Message:TWMSize);
begin
inherited ;
FLabel.Width := Message.Width;
//FLabel.Height:= Int((Message.Height)/2);
FBitBtn.Width := Message.Width;
//TBitBtn.Height:= (Message.Height)/2;
end;
//Fpanel := Message.Height;

constructor TMywin4.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FBitBtn :=TBitbtn.Create(Self);
FBitBtn.Parent := Self;
FBitBtn.Left:=Self.Left+Self.Width;
FBitBtn.Top:=Self.Top;

FLabel:=TLabel.Create(Self);
FLabel.Parent:=Self;
FLabel.Left:=Self.Left;
FLabel.Height:=FBitbtn.Height;
FLabel.Top:=Self.Top-FBitBtn.Height;


Width:=FLabel.Width;
Height:=FLabel.Height+FBitbtn.Height;
end;



procedure TMywin4.SetText(Value:String);
begin
FLabel.Caption:=Value;
end;

function TMywin4.GetText:String;
begin
Result:=FLabel.Caption;
end;

procedure TMywin4.SetCaption(Value:String);
begin
FBitbtn.caption:=Value;
end;

function TMywin4.Getcaption:String;
begin
Result:=FBitbtn.Caption;
end;

procedure TMywin4.SetFont(Value:TFont);
begin
if Assigned(Flabel.Font) then
FLabel.Font.Assign(Value);
FBitbtn.Font.Assign(Value);
end;

function TMywin4.GetFont:TFont;
begin
Result:=FLabel.Font;
end;

procedure TMywin4.SetOnButtonClick(Value:TNotifyEvent);
begin
FBitbtn.Onclick:=Value;
end;

function TMywin4.GetOnButtonClick:TNotifyEvent;
begin
Result:=FBitbtn.onclick;
end;

procedure TMywin4.SetGlyph(Value: TBitmap);
begin
if FGlyph<>Value then
begin
FGlyph.Assign(Value);
end;
end;

function TMywin4.GetGlyph:TBitmap;
begin
Result:=FGlyph;
end;

destructor TMywin4.Destroy;
begin
FBitBtn.Free;
FLabel.Free;
FGlyph.Free;
inherited Destroy;
end;

procedure Register;
begin
RegisterComponents('Samples', [TMywin4]);
end;

end.
问题1:是在object inspector里面选glyph时后,bitbtn 没有显示。运行出现
project project1.exe raise exception class EreadError with message 'Invalid property path'.
问题2:我不想设死控件高度!我想控制bitbtn和label一样搞,各占高度的一半,应该怎么改?
...全文
45 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
vargent77 2003-10-08
  • 打赏
  • 举报
回复
高度这里还是又问题,只能调整那个label的大小,那个button没变化?而且text属性没有显示?
感谢FrameSniper(§绕瀑游龙§) 解决了我Glyph的问题。
FrameSniper 2003-10-03
  • 打赏
  • 举报
回复
首先,偶想说一点,楼主对Font属性的设计个人感觉有点问题,Font属性可以直接使用TWinControl从TControl继承下来的Font属性,在构造器里派生TBitBtn和TLabel子对象的时候直接指定他们的ParentFont属性为True就可以了,以后对组件的Font的设置都将影响到子组件的Font内容....

另外,对于Glyph这个属性,可以去掉FGlyph这个私有数据的申明,在属性Glyph的读写方法中直接操作FBitBtn的Glyph属性就可以了,如下:

procedure TMywin4.SetGlyph(Value: TBitmap);
begin
if FBitBtn.Glyph<>Value then
FBitBtn.Glyph.Assign(Value);
end;

function TMywin4.GetGlyph:TBitmap;
begin
Result:=FBitBtn.Glyph;
end;
这样操作也就没有必要再多创建一个TBitMap对象而忽略FBitBtn本身对应对象的存在了!

至于高度问题,你直接在WM_SIZE消息处理器使用注释部分的操作不可以吗?
seion 2003-10-03
  • 打赏
  • 举报
回复
UP
Cstarter 2003-10-03
  • 打赏
  • 举报
回复
我没有看到您对FBitBtn的位图赋值语句啊

Cstarter 2003-10-02
  • 打赏
  • 举报
回复
关注!
vargent77 2003-09-30
  • 打赏
  • 举报
回复
constructor TMywin6.Create(AOwner:TComponent);
begin
inherited Create(AOwner);

FBitBtn :=TBitbtn.Create(Self);

FBitBtn.Parent := Self;
FBitBtn.Left:=Self.Left+Self.Width;
FBitBtn.Top:=Self.Top;
FGlyph:=TBitmap.Create;
FLabel:=TLabel.Create(Self);
FLabel.Parent:=Self;
FLabel.Left:=Self.Left;
FLabel.Height:=FBitbtn.Height;
FLabel.Top:=245;//Self.Top-FBitBtn.Height;
Width:=FLabel.Width;
Height:=FLabel.Height+FBitbtn.Height;
end;
这样对了吧?
zhoutian618 2003-09-30
  • 打赏
  • 举报
回复
procedure TMywin5.SetGlyph(Value: TBitmap);
begin
FGlyph:=TBitmap.Create;//放到CREATE方法中去啊。
if FGlyph<>Value then
begin
FGlyph.Assign(Value);
end;
end;
wxjh 2003-09-30
  • 打赏
  • 举报
回复
如果伟图有问题,你就应该进行设计一个图形装载模板了,可以使用DIGSIN.PAS单元离现成的,自己看看
vargent77 2003-09-30
  • 打赏
  • 举报
回复
已改成这样!问题依旧
procedure TMywin5.SetGlyph(Value: TBitmap);
begin
FGlyph:=TBitmap.Create;
if FGlyph<>Value then
begin
FGlyph.Assign(Value);
end;
end;
wxjh 2003-09-30
  • 打赏
  • 举报
回复
错误问题单步调试一下看看就知道了,你的这个组件很简单的
wxjh 2003-09-30
  • 打赏
  • 举报
回复
FBitBtn没有VISIBLE
zhoutian618 2003-09-30
  • 打赏
  • 举报
回复
FGlyph: TBitmap没有初使化啊。

要在Create方法中初使化啊。

FGlyph:=TBitmap.Create;///////////
vargent77 2003-09-30
  • 打赏
  • 举报
回复
你的意思是?property LabelPosition: TLabelPosition read FLabelPosition write SetLabelPosition;
vargent77 2003-09-30
  • 打赏
  • 举报
回复
labelededit更正????
yanhuizen 2003-09-30
  • 打赏
  • 举报
回复
是labelededit更正
yanhuizen 2003-09-30
  • 打赏
  • 举报
回复
你最好先看一下VCL下的ExtCtrls.pas中的lableedit问题就解决了!!!

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧