本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17251009
编辑框

编辑框也叫文本框,是典型的窗口可视化组件,既可以用来输入文本,也可以用来显示文本,是程序设计中最常用的组件之一,可以获取用户输入的许多信息。Pascal中的编辑框由类Tedit实现,该类的定义如下:

TEdit = class(TCustomEdit)

property AutoSelect: Boolean; read write;

property AutoSize: Boolean; read write;

property BorderStyle: TBorderStyle; read write;

property CharCase: TEditCharCase; read write;

property Color: TColor; read write;

property Font: TFont; read write;

property HideSelection: Boolean; read write;

property MaxLength: Integer; read write;

property PasswordChar: Char; read write;

property ReadOnly: Boolean; read write;

property Text: String; read write;

property OnChange: TNotifyEvent; read write;

property OnClick: TNotifyEvent; read write;

property OnDblClick: TNotifyEvent; read write;

property OnKeyDown: TKeyEvent; read write;

property OnKeyPress: TKeyPressEvent; read write;

property OnKeyUp: TKeyEvent; read write;

end;

该类的层次模型如下:

下面的代码将演示创建编辑框,以及编辑框的Text属性:

[setup]

AppName=Test

AppVerName=TEST

DefaultDirName="E:\TEST"

AppVersion=1.0

[files]

Source: "F:\desktop\Inno\ipmsg.exe";Flags:dontcopy

[code]

var

myPage:TwizardPage;

myBtn:TButton;

ed1,ed2,ed3:TEdit;

procedure ClickmyBtn(Sender: TObject);

begin

ed3.Text:=ed1.Text+' '+ed2.Text;

end;

procedure InitializeWizard();

begin

myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面');

myBtn:=TButton.Create(myPage);

myBtn.Parent:=myPage.Surface;

myBtn.Caption:='点我~';

myBtn.OnClick:=@ClickmyBtn;

ed1:=TEdit.Create(myPage);

ed1.Parent:=myPage.Surface;

ed1.Top:=myBtn.Top+30;

ed1.Width:=myBtn.Width;

ed2:=TEdit.Create(myPage);

ed2.Parent:=myPage.Surface;

ed2.Top:=ed1.Top+30;

ed2.Width:=myBtn.Width;

ed3:=TEdit.Create(myPage);

ed3.Parent:=myPage.Surface;

ed3.Top:=ed2.Top+30;

ed3.Width:=myBtn.Width;

end;

属性Text用于设置或获取文本框中的内容,注意不管是设置还是获取,参数一定必须是String的类型,运行效果如下:

如果是想实现两个数的代数运算,而不是字符串的拼接,则按钮的OnClick过程应该做如下修改:

procedure ClickmyBtn(Sender: TObject);

var

a,b:Extended;

begin

a:=StrToFloat(ed1.Text);

b:=StrToFloat(ed2.Text);

ed3.Text:=FloatToStr(a+b);

end;

StrToFloat和FloatToStr分别实现字符串转实数,实数转字符串。在第一、第二个文本框中输入数值后,点击按钮将第三个文本框中的内容设置为两数的和。下面再说说其他的属性。修改代码段如下:

[code]

var

myPage:TwizardPage;

myBtn:TButton;

ed1,ed2,ed3:TEdit;

a,b,c:String;

procedure ClickmyBtn(Sender: TObject);

begin

a:=ed1.Text;

b:=ed2.Text;

c:=a+b;

ed3.Text:=c;

end;

procedure InitializeWizard();

begin

myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面');

myBtn:=TButton.Create(myPage);

myBtn.Parent:=myPage.Surface;

myBtn.Caption:='点我~';

myBtn.OnClick:=@ClickmyBtn;

ed1:=TEdit.Create(myPage);

ed1.Parent:=myPage.Surface;

ed1.Top:=myBtn.Top+30;

ed1.Width:=myBtn.Width;

ed1.CharCase:=ecUpperCase;{大写}

ed1.ShowHint:=True;

ed1.Hint:='字母将会变为大写';

ed2:=TEdit.Create(myPage);

ed2.Parent:=myPage.Surface;

ed2.Top:=ed1.Top+30;

ed2.Width:=myBtn.Width;

ed2.PasswordChar:='#';{密码样式}

ed3:=TEdit.Create(myPage);

ed3.Parent:=myPage.Surface;

ed3.Top:=ed2.Top+30;

ed3.Width:=myBtn.Width*2;

ed3.ReadOnly:=true;{只读}

end;

上面介绍了四个属性:CharCase将设置文本显示的格式,可以有三个值:(ecNormal, ecUpperCase, ecLowerCase,分别为正常方式,大写方式,小写方式;PasswordChar属性将输入的文本替换为制定的样式;ReadOnly属性将使得该文本框不接受用户输入;Hint和ShowHint属性是用户的鼠标停留在该文本框上时,给出相应的提示文本,注意只有在ShowHint设置为True的时候才会显示。

另外,编辑框也能对一些事件做出相应,例如单击、双击,文本内容发生变化等,实现起来和按钮的差不错,这里就不再啰嗦了。最后需要介绍的是三个处理按键的属性: OnKeyDown、OnKeyPress和OnKeyUp

这三个属性是当用户光标停留在该文本框中时,当用户按下了键盘上的某个键时,会调用该属性指定的过程,测试代码如下:

[code]

var

myPage:TwizardPage;

ed:TEdit;

procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

begin

if (key=67) and (Shift=[ssAlt]) then

Msgbox('你按下了Alt+c',MBInformation,MB_OK);

end;

procedure InitializeWizard();

begin

myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面');

ed:=TEdit.Create(myPage);

ed.Parent:=myPage.Surface;

ed.OnKeyDown:=@EditKeyDown;

end;

在编辑框中输入时,用户按下Alt+C组合时,将会做出响应,弹出一个消息框,这样可以对我们感兴趣的按键组合做出相应的动作,例如我们想屏蔽粘贴这项功能,则修改代码如下:

procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

begin

if (key=86) and (Shift=[ssCtrl]) then

Msgbox('粘贴无效,请手动输入',MBInformation,MB_OK);

ed.text:='';

end;

不过这里要说明的是,这还不能屏蔽右键粘贴,只是屏蔽了Ctrl+V的方式。另外两个按键属性和这里介绍的KeyDown差不多,可对照测试一下。

(转)Inno Setup入门(十八)——Inno Setup类参考(4)的更多相关文章

  1. Inno Setup入门(八)——有选择性的安装文件

    这主要使用[Components]段实现,一个演示的代码如下: [setup] ;全局设置,本段必须 AppName=Test AppVerName=TEST DefaultDirName=" ...

  2. Inno Setup入门(八)——有选择性的安装文件

    这主要使用[Components]段实现,一个演示的代码如下: [setup] ;全局设置,本段必须 AppName=Test AppVerName=TEST DefaultDirName=" ...

  3. (转)Inno Setup入门(八)——有选择性的安装文件

    本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250827 这主要使用[Components]段实现,一个演示的代 ...

  4. [译]Kinect for Windows SDK开发入门(十八):Kinect Interaction交互控件

    本文译自 http://dotneteers.net/blogs/vbandi/archive/2013/03/25/kinect-interactions-with-wpf-part-i-getti ...

  5. Android入门(十八)服务

    原文链接:http://www.orlion.ga/674/ 一.定义一个服务 创建一个项目ServiceDemo,然后在这个项目中新增一个名为 MyService的类,并让它继承自 Service, ...

  6. [WebGL入门]十八,利用索引缓存来画图

    注:文章译自http://wgld.org/.原作者杉本雅広(doxas),文章中假设有我的额外说明.我会加上[lufy:].另外,鄙人webgl研究还不够深入,一些专业词语,假设翻译有误,欢迎大家指 ...

  7. Inno Setup入门(一)——最简单的安装脚本

    地址:http://379910987.blog.163.com/blog/static/3352379720110238252326/ 一个最简单的安装脚本: 1.最简单的安装文件脚本: [setu ...

  8. Inno Setup入门(十六)——Inno Setup类参考(2)

    Inno Setup入门(十六)——Inno Setup类参考(2) http://379910987.blog.163.com/blog/static/33523797201112755641236 ...

  9. Inno Setup入门(十五)——Inno Setup类参考(1)

    分类: Install Setup 2013-02-02 11:27 536人阅读 评论(0) 收藏 举报 nno setup脚本能够支持许多的类,这些类使得安装程序的功能得到很大的加强,通过对这些类 ...

  10. (转)Inno Setup入门(十五)——Inno Setup类参考(1)

    本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250955 nno setup脚本能够支持许多的类,这些类使得安装 ...

随机推荐

  1. lvs fullnat部署手册(一)fullnat内核编译篇

    标签:kernel rpm lvs fullnat 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://shanks.blog.51c ...

  2. gridview 后台增加列

    BoundField field1 = null; field1 = new BoundField();  //实例化 field1.HeaderText = "序号";field ...

  3. yii2 实现excel导出功能

    官方教程地址:http://www.yiiframework.com/extension/yii2-export2excel/ 安装: Either run php composer.phar req ...

  4. JavaWeb过滤器——登录过滤

    一般来说简单且常用的过滤器使用方法,我觉得除了配置字符编码的过滤之外就是登录器的过滤了 登录过滤器的主要过程可以 一句话来概括:首先在登录的时候把指定好的标志放在session中,操作过滤的时候根据s ...

  5. Shell 命令行批量处理图片文件名

    Shell 命令行批量处理图片文件名 从网上下载了一堆图片,有的是*.jpg的,有的是*.jpeg的.并且文件名有长有短,很是糟心.因此,我想把这些文件给全部整理好,当然是用shell来处理啦! 说干 ...

  6. PHP简单实例

    <?php /** * @author admin * @copyright 2016 *编程实现2+4+6+…+100. * $sum = 0; for($i=2;$i<=100;$i+ ...

  7. WEB服务器都在做哪些工作?

    作为WEB开发人员,我们肯定应该要知道WEB服务器都在做哪些工作,这里简单列举一下,有时间然后详细说明. (1)建立连接——接受一个客户端连接. (2)接收请求——从网络中读取一条 HTTP 请求报文 ...

  8. 我在ubuntu14.04安装使用的软件

    搜狗拼音sougoupinyin:sudo add-apt-repository ppa:fcitx-team/nightly && sudo apt-get updatesudo a ...

  9. 每天一个linux命令:【转载】rmdir命令

    今天学习一下linux中命令: rmdir命令.rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删 ...

  10. NSURLSession学习笔记(三)Download Task

    NSURLSession的Download Task用于完成下载任务,本文介绍如何创建断点续传的下载任务和后台下载任务. 我们直接从分析Demo入手: 故事板如下: 只有一个View Controll ...