2009年1月9日
摘要: 本例在 Delphi 2007 和 Delphi 2009 中均调试通过, 运行效果图:代码文件:unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: T... 阅读全文
posted @ 2009-01-09 15:41 东睿 阅读(313) 评论(0) 推荐(0)
摘要: //绝对值: Absvard: Real;v: Variant;begind := Abs(-1.2);ShowMessage(FloatToStr(d)); {1.2}v := '-100';ShowMessage(v); {-100; v 是变体类型无需转换}v := Abs(v);ShowMessage(v); {100; 如果变量的确是个数字, 变体类型也是可以取绝对值}end;//返回整... 阅读全文
posted @ 2009-01-09 13:30 东睿 阅读(178) 评论(0) 推荐(0)
摘要: 测试效果图:unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Memo1: TMemo;procedure Button1Click(... 阅读全文
posted @ 2009-01-09 11:25 东睿 阅读(180) 评论(0) 推荐(0)
摘要: 如果参数在函数中不可能修改, 一定要使用 const;不然, 编译器就会:假定先修改, 先要备份; 使用前后要增减引用计数; 还要套上 try finally.指定了 const 就可以避免以上过程从而提高效率.测试效果图:unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Contro... 阅读全文
posted @ 2009-01-09 11:10 东睿 阅读(297) 评论(1) 推荐(0)
摘要: 链表与数组的异同: 1、数组中的元素在内存中是连续的; 链表不是. 2、数组的内存是一次性分配和释放的; 链表不是. 3、链表定位元素是顺藤摸瓜; 数组是一步到位, 更快. 4、链表可以方便的插入和删除元素; 用数组实现即麻烦有费时, 基本没人这样做. 5、链表拥有更多扩展的潜力! 阅读全文
posted @ 2009-01-09 11:05 东睿 阅读(201) 评论(0) 推荐(0)
摘要: 本例效果图: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2:... 阅读全文
posted @ 2009-01-09 10:59 东睿 阅读(263) 评论(0) 推荐(0)
摘要: 如果在结构中再拿出 4 个字节的地址空间指向上一个节点, 就成了双向链表了. 本例效果图: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm... 阅读全文
posted @ 2009-01-09 10:55 东睿 阅读(316) 评论(0) 推荐(0)
摘要: procedure TForm1.FormCreate(Sender: TObject); var Str: string; pStr: PString; begin Str := 'Delphi 2007'; pStr := @Str; {用 @ 获取指针} ShowMessage(pStr^); {Delphi 2007} Str := 'Delphi 2... 阅读全文
posted @ 2009-01-09 10:46 东睿 阅读(565) 评论(0) 推荐(0)
摘要: //分割字符串 ExtractStrings var s: String; List: TStringList; begin s := 'about: #delphi; #pascal, programming'; List := TStringList.Create; ExtractStrings([';',',',':'],['#',' '],PChar(s),List);... 阅读全文
posted @ 2009-01-09 10:36 东睿 阅读(226) 评论(0) 推荐(0)
摘要: 尽管使用 TIniFile 类很方便, 但我觉得还是用系统 API 操作更顺手, 读写各只需要一行代码, 也不用 uses IniFiles. 本例效果图: 代码文件: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dia... 阅读全文
posted @ 2009-01-09 10:25 东睿 阅读(622) 评论(0) 推荐(0)