第一次开发控件,大家来指点一下

youlinkr 2004-12-15 04:30:00
控件其实就是一个Panel和两个Image的整合,Image在Panel里面,因为需要同时创建三个控件,故写之,源码如下:
unit IPanel;

interface

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

type
TIPanel = class(TPanel)
private
FImg:TImage;
FImgPaste:TImage;
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Img : TImage read FImg write FImg;
property ImgPaste:TImage read FImgPaste write FImgPaste;
end;

procedure Register;

implementation

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

constructor TIPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FImg:=TImage.Create(AOwner);
FImg.Parent:=Self;
FImg.Name:='Img';////////////************
FImgPaste:=TImage.Create(AOwner);
FImgPaste.Parent:=Self;
FImgPaste.Name:='ImgPaste';/////////////**************
FImg.Top:=0;
FImg.Left:=0;
FImg.Width:=Self.Width-1;
FImg.Height:=Self.Height-1;
FImg.Visible:=False;

end;

destructor TIPanel.Destroy;
begin
FImg.Free;
FImgPaste.Free;
inherited Destroy;
end;

end.

以上///////*******处,应用控件时,编译程序,会提示命名重复,若去掉这两句,设计时,控件放置在窗体上,发现两Image控件没有名称,不知怎样访问,其实目的很简单,就是想IPanel.Img这样访问其中一Image控件,请大虾帮忙
...全文
100 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
paybfly 2004-12-20
  • 打赏
  • 举报
回复
做一个模板就行了
cdsgajxlp 2004-12-20
  • 打赏
  • 举报
回复
FImg.Name:='Img';////////////************ //不要
FImgPaste:=TImage.Create(self);
Blakhawk 2004-12-20
  • 打赏
  • 举报
回复
FImgPaste:=TImage.Create(nil);
FImgPaste.Parent:=Self;
去掉FImg.Name:='Img';////////////************
jinjazz 2004-12-17
  • 打赏
  • 举报
回复
把基本代码写好然后选中panel点击菜单component点击create component template就好了

5,388

社区成员

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

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