在 Delphi 2009 中, for in 循环都能用在什么地方?
摘要:一、遍历 TStrings var List: TStrings; s: string; begin List := TStringList.Create; List.CommaText := 'aaa,bbb,ccc'; for s in List do ShowMessage(s); List.Free; end; 二、遍历数组 var A...
阅读全文
posted @
2008-11-12 13:43
万一
阅读(11327)
推荐(0) 编辑
在 case 语句中使用字符串
摘要:非常遗憾 Delphi 的 case 语句不支持字符串, 但我觉得这也可能是基于效率的考量; 如果非要在 case 中使用字符串, 也不是不可以变通, 这里提供了五种方法. 本例效果图: 代码文件: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls...
阅读全文
posted @
2008-07-08 03:46
万一
阅读(14701)
推荐(0) 编辑
raise 语句: 抛出异常
摘要://例1: begin raise Exception.Create('抛出异常'); end; //例2: begin raise Exception.CreateFmt('%s %d', ['错误代码:', 999]); end; //例3: var exc: Exception; begin exc := Exception.Create('发现异常'); ra...
阅读全文
posted @
2008-03-27 23:26
万一
阅读(10186)
推荐(0) 编辑
for 循环的例子
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton...
阅读全文
posted @
2008-01-23 01:22
万一
阅读(8012)
推荐(0) 编辑
with 语句的妙用
摘要://一般写法 var MyForm1: TForm1; begin MyForm1 := TForm1.Create(nil); MyForm1.ShowModal; MyForm1.Free; end; //用 with 语句重写 with TForm1.Create(nil) do begin ShowModal; Free; end;
阅读全文
posted @
2008-01-23 01:07
万一
阅读(5837)
推荐(0) 编辑
程序流程的辅助控制
摘要:Abort //激发异常退出,如果在 try 块中,except 和 finally 的程序会执行 Exit //正常退出,如果在 try 块中,except 和 finally 的程序会执行 Halt //非正常结束程序,可有 Integer 参数给操作系统,windows 程序一般使用:Application.Terminate RunError //生成一个运行时错误,并退出程序。参数是 ...
阅读全文
posted @
2007-12-01 20:18
万一
阅读(5906)
推荐(0) 编辑
goto 语句
摘要:procedure TForm1.Button1Click(Sender: TObject); var x: Integer; label n1,n2,n3,4; //goto的标签可以是标识符, 也可以是0..9999的数字 begin x := 0; goto n3; n1: x := x+1; n2: x := x+2; n3: x := x+3; 4: ...
阅读全文
posted @
2007-11-26 22:55
万一
阅读(5447)
推荐(0) 编辑
uses 子句的写法
摘要://uses 子句一般这样写 uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; //这样写更清晰,因为Delphi忽略换行 uses Windows, Messages, SysUtils, Variants, Classes, Graph...
阅读全文
posted @
2007-11-26 11:50
万一
阅读(7018)
推荐(0) 编辑