constructor TMySpeedButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Caption := Name;
end;
begin
inherited Create(AOwner);
Caption := Name;
end;
解决方案 »
- 关于“TList”的疑惑!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 写了个函数,查询数据第一条记录
- 請問進度條如何寫?
- 如何判断EXCEL文件已打开
- 请问如何取到其它应用程序中的控件句柄?如(QQ的登陆对话框中的两个edit控件)
- 简单问题,高分相送!
- 如何以最大的效率将数据库查询结果载入StringGrid?
- 为什么我打开网页的时候经常问我“出现了运行时间错误”
- Delphi与SQL Server到底要怎么关联
- 最近我的delphi有个问题:设计菜单时不能输入“历史”二个字,“史”显示不出,还发现在excel2000中,打开文件对话框中左边的“历史”也是不显示“史”字,不知为什么?
- 那里有delphi 5 开发人员指南的电子版可以下载??
- 如何将数据库文件和应用程序绑定\\?
unit RunButton;
interface
uses
Windows, Messages, SysUtils,shellapi, Classes, Graphics, Controls, Forms, Dialogs,
Buttons;
type
TcommandLine=type string;
TRunButton = class(TSpeedButton)
private
Fcaption:Tcaption;
FcommandLine:TcommandLine;
procedure SetCommandLine(value:TcommandLine);
procedure setcaption(value:Tcaption);
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(Aowner:Tcomponent);override;
procedure Click;override;
{ Public declarations }
published
property Caption:Tcaption read Fcaption write setcaption;
property CommandLine:TcommandLine read FcommandLine write SetCommandLine;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TRunButton]);
end;
procedure TrunButton.setcaption(value:Tcaption);
begin
inherited;
Fcaption:=value;
repaint;
end;
constructor TrunButton.create(Aowner:Tcomponent);
begin
inherited create(Aowner);
setcaption(Name);
width:=45;
height:=45;
end;
Function IsExecutableFile(value:TcommandLine):boolean;
begin
result:=(uppercase(ExtractFileExt(value))='.EXE');
end;
procedure Trunbutton.SetCommandLine(value:TcommandLine);
var
Icon:Ticon;
begin
if not IsExecutableFile(value) then raise exception.Create(value+'不是一个可执行文件!');
if not FileExists(value) then raise exception.Create(value+'文件不存在!');
FcommandLine:=value;
Icon:=Ticon.Create;
try
icon.Handle:=ExtractIcon(hinstance,Pchar(FcommandLine),0);
with Glyph do
begin
canvas.brush.style:=bssolid;
canvas.FillRect(canvas.cliprect);
width:=icon.Width;
height:=Icon.Height;
canvas.Draw(0,0,icon);
end;
finally
icon.Free;
end;
end;
function processexecute(commandline:TcommandLine;cshow:word):integer;
var
rslt:longbool;
startupinfo:Tstartupinfo;
processinfo:Tprocessinformation;
begin
fillchar(startupinfo,sizeof(Tstartupinfo),#0);
with startupinfo do
begin
cb:=sizeof(Tstartupinfo);
dwflags:=startf_useshowwindow or startf_forceonfeedback;
wshowwindow:=cshow;
end;
rslt:=createprocess(pchar(commandline),nil,nil,nil,false,normal_priority_class,nil,
nil,startupinfo,processinfo);
if rslt then
with processinfo do
begin
waitforinputidle(hprocess,infinite);
closehandle(hthread);
closehandle(hprocess);
result:=0;
end
else
result:=getlasterror;
end;
procedure Trunbutton.Click;
var
rean:word;
begin
inherited click;
rean:=ProcessExecute(FcommandLine,sw_shownormal);
if rean<>0 then
raise exception.Create('错误地执行了程序:'+inttostr(rean));
end;
end.
procedure SetParent(AParent: TWinControl); override;
procedure TMySpeedButton.SetParent(AParent: TWinControl);
begin
inherited;
if AParent <> nil then
Caption := Name;
end;
目前在object inspector中,caption值已经可以根据控件的加入而变化,但在控件上不显示caption值,如何处理?please help.
interface
uses
Windows, Messages, SysUtils,shellapi, Classes, Graphics, Controls, Forms, Dialogs,
Buttons;
type
TcommandLine=type string;
TRunButton = class(TSpeedButton)
private
Fcaption:Tcaption;
FcommandLine:TcommandLine;
procedure SetCommandLine(value:TcommandLine);
procedure setcaption(value:Tcaption);
{ Private declarations }
protected
procedure SetParent(AParent: TWinControl); override;
{ Protected declarations }
public
constructor create(Aowner:Tcomponent);override;
procedure Click;override;
{ Public declarations }
published
// property Caption:Tcaption read Fcaption write setcaption;
property CommandLine:TcommandLine read FcommandLine write SetCommandLine;
{ Published declarations }
end;
procedure Register;
implementation
procedure TrunButton.SetParent(AParent: TWinControl);
begin
inherited;
if AParent <> nil then
Caption := Name;
end;procedure Register;
begin
RegisterComponents('Samples', [TRunButton]);
end;
procedure TrunButton.setcaption(value:Tcaption);
begin
inherited;
Fcaption:=value;
// repaint;
end;
constructor TrunButton.create(Aowner:Tcomponent);
begin
inherited create(Aowner);
// setcaption(Name);
width:=45;
height:=45;
end;
Function IsExecutableFile(value:TcommandLine):boolean;
begin
result:=(uppercase(ExtractFileExt(value))='.EXE');
end;
procedure Trunbutton.SetCommandLine(value:TcommandLine);
var
Icon:Ticon;
begin
if not IsExecutableFile(value) then raise exception.Create(value+'不是一个可执行文件!');
if not FileExists(value) then raise exception.Create(value+'文件不存在!');
FcommandLine:=value;
Icon:=Ticon.Create;
try
icon.Handle:=ExtractIcon(hinstance,Pchar(FcommandLine),0);
with Glyph do
begin
canvas.brush.style:=bssolid;
canvas.FillRect(canvas.cliprect);
width:=icon.Width;
height:=Icon.Height;
canvas.Draw(0,0,icon);
end;
finally
icon.Free;
end;
end;
function processexecute(commandline:TcommandLine;cshow:word):integer;
var
rslt:longbool;
startupinfo:Tstartupinfo;
processinfo:Tprocessinformation;
begin
fillchar(startupinfo,sizeof(Tstartupinfo),#0);
with startupinfo do
begin
cb:=sizeof(Tstartupinfo);
dwflags:=startf_useshowwindow or startf_forceonfeedback;
wshowwindow:=cshow;
end;
rslt:=createprocess(pchar(commandline),nil,nil,nil,false,normal_priority_class,nil,
nil,startupinfo,processinfo);
if rslt then
with processinfo do
begin
waitforinputidle(hprocess,infinite);
closehandle(hthread);
closehandle(hprocess);
result:=0;
end
else
result:=getlasterror;
end;
procedure Trunbutton.Click;
var
rean:word;
begin
inherited click;
rean:=ProcessExecute(FcommandLine,sw_shownormal);
if rean<>0 then
raise exception.Create('错误地执行了程序:'+inttostr(rean));
end;
end.
奇怪问题:我在此事件最后一行中加入showmessage(name)发现在设计期时当把此控件加入form时,此事件触发两次???
而且第一次showmessage(name)是空,此时控件还在窗体的左上角,而第二次时showmessage(name)有了值,并且此时控件才移动到指定的位置,这是为什么?