《Mastering Delphi 6》学习笔记之六

Mastering Delphi 7 英文版 Delphi两大系列之一的MD系列。这是针对Delphi7的英文原版。 立即下载

《Mastering Delphi 6》学习笔记之六

Delphi 6中对RTL增加了不少函数和Helper Class,虽然不算翻天覆地的大变化,不过确实方便不少。如果有时间的话,建议大概浏览一下新增的StrUtils,DateUtils和ConvUtils这些单元,相信会发现一些有趣的东西。

如果要得到操作系统的信息,如下即可:

  case Win32Platform of

    VER_PLATFORM_WIN32_WINDOWS:ShowMessage ('Windows 9x');

    VER_PLATFORM_WIN32_NT:ShowMessage ('Windows NT');

   end;

   ShowMessage ('Running on Windows:'+IntToStr (Win32MajorVersion)+'.'

               + IntToStr (Win32MinorVersion)+

               ' ((Build '+IntToStr (Win32BuildNumber)+

')'+#10#13 +'Update:'+Win32CSDVersion);

没有理由再调用GetVersion或者GetVersionEx了。

 

Delphi 6中的SysUtils增加了几个比较有用的Bool/Str conversion函数,声明如下:

function StrToBool(const S: string): Boolean;

function StrToBoolDef(const S: string; const Default: Boolean): Boolean;

function TryStrToBool(const S: string; out Value: Boolean): Boolean;

function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;

不用看帮助,你也应该明白这几个函数如何使用了。其中BoolToStr可能是比较常用的一个,如果不指定UseBoolStrs参数,那么返回的将会是B的Ord形式,例如,BoolToStr(True)将返回’-1’。而BoolToStr(True,True)则返回’True’。返回值取决于SysUtils单元中声明的TrueBoolStrs /FalseBoolStrs /DefaultTrueBoolStr /DefaultFalseBoolStr这几个值。遗憾的是DefaultTrueBoolStr是常量,不能够用一般的方法改变。如果要符合汉语的习惯,那么只好这样:

   if Length(TrueBoolStrs)<2 then begin

      Setlength(TrueBoolStrs,2);

      TrueBoolStrs[0] := '真';

      TrueBoolStrs[1] := DefaultTrueBoolStr;

   end;

   str := BoolToStr(True,True);

   ShowMessage(str);

另外一些新的转换函数,例如FloatToCurr,FloatToDateTime,TryStrToFloat,TryStrToCurr等在某些情况下也是很有用的。

 

一个有趣并且好用的新函数:IfThen。它有Integer,Int64,Double和string四个重载版本,可以应付一般的需要,比如:

Sex := IfThen(bMale,‘男’,‘女’);

这样比If...Then...End简洁多了,很像是C++中的?:.

 

关于浮点操作也有许多增强函数.SameValue检查两个变量是否相等(或者相近到可以忽略其差别的地步)。CompareValue的功能也类似。DivMod可以将Div和Mod两种操作在一个函数中完成。RoundTo完成进位工作,例如,

RoundTo(1234.567,3);     // 返回1000

RoundTo(1234.567,-2);    // 返回1234.57

 

DateTime函数有这样一些增强:

function DayOf(const AValue:TDateTime):Word;

function HourOf(const AValue:TDateTime):Word;

function WeekOfYear(const AValue:TDateTime):Integer;

function HourOfWeek(const AValue:TDateTime):Integer;

function SecondOfHour(const AValue:TDateTime):Integer;

function DaysBetween(const ANow,AThen:TDateTime):Integer;

function WithinPastDays(const ANow,AThen:TDateTime;const ADays:Integer):Boolean;

 

下面的例子显示了一些新增的字符串操作:

ShowMessage(DupeString(‘Hello’,3));  //返回HelloHelloHello

ShowMessage(ReverseString(‘Hello’)); //返回olleH

 

Delphi目前也提供了对复数的支持。例如,

var

v1,v2:Variant;

begin

v1 :=VarComplexCreate (10,12);

v2 :=VarComplexCreate (10,1);

ShowMessage (v1 +v2 +5);

这个例子也反映了Object Pascal中对于Variant提供了类似于操作符重载的方法。不过,由于Variant效率不高和维护困难,一般不建议使用它们。

 

Mastering Delphi 7 中文版(Delphi 7从入门到精通) 这不是一本入门的书.支持请点击:http://www.netyi.net/in.asp?id=nemeses我下这本书要积分的, 你的点击可以给我积一分.(1IP仅一次). 立即下载

相关推荐

Mastering Delphi 7

mastering delphi 7 english edition. NOTICE: pdf converted from chm.

Mastering Delphi7 阅读笔记(摘要) 续

 第12章  从COM到COM+  本章主要内容   OLE和COM技术历史简介   实现IUnknown   第一个COM服务器   自动化   编写一个自动化服务器   使用复合文档   介绍AxtiveX控件   编写ActiveX控件   介绍COM+   Delphi 7中的COM和.NET    OLE和COM技术历史简介   所有以对象链接和嵌入(OLE)技术开发的部件,都是动态数据

qffhq 点积 2557

Mastering Delphi7 Delphi7 开发指南中文版(三个分卷之2)

Mastering Delphi7 Delphi7

《Mastering Delphi 6》学习笔记之六 (转)

《Mastering Delphi 6》学习笔记之六 (转)[@more@] ...

csd3176的博客 83

mastering delphi 7 英文 epub版

mastering delphi 7 英文 epub版,方便在移动设备上阅读,已经用静读天下,ireader测试,可以正常阅读

mastering_delphi_7_code.rar

Delphi 7 代码,Marco Cantu - Mastering Delphi 7 随书源码.

《Mastering Delphi 6学习笔记》之二

 《Mastering Delphi 6学习笔记》之二 本文是我在阅读《Mastering Delphi 6》一书过程中的一些心得笔记,一方面因为原书是英文版,所以将一些我认为比较重要的部分整理和摘录出来,记以备忘;另一方面也希望和大家一起分享《Master Delphi 6》这本好书和Delphi 6这一优秀工具。第一部分《Object TreeView简要说明》已经贴出,从这一部分

weizhisheng的专栏 1085

Oracle Patch清理

- opatch clean的帮助,该命令清除.patch_storage directory文件夹下的'restore.sh,make.txt' files and 'scratch,backup'-- 执行完毕后,貌似没有变化,可能和自己环境有关(19年开始测试补丁,基本上每个季度都测试,后面把又把数据库用RMAN做了迁移,又转换成了PDB模式)。在对Oracle安装补丁后,会发现OS上被占用了大量的空间,本文档清理Opatch过程中的一些文件,释放空间。--清理后空间,剩余25G。

文档搬运工 1075

《Mastering Delphi 6》学习笔记之十一

CLX及其它 《Mastering Delphi 6》中提到Object Pascal中有一个TBits类,用来进行二进制位操作。我看过这一段之后马上去找,果然在Classes单元中找到了它。这个类的声明相当简单,不过我看过后感慨很多。如果不知道这个类的存在,我以后可能还要在需要操作二进制位的时候辛辛苦苦的写一大串代码(我以前也写过不少这样的代码),要是能够早点知道有这个类的话该有多好!我

weizhisheng的专栏 1247

hpm6750evk2开发板(四)TCP回送(1000M网口)

再接下来我们修改代码,先找到配置网速的地方,肯定是在enet的初始化函数里面,我们一个函数一个函数找,也可以用单步调试一步一步找,结果发现是在enet_init函数里面调用的rtl8211_basic_mode_default_config函数配置网速的,我们把enet_phy_port_speed_100mbps改为enet_phy_port_speed_1000mbps,重新编译运行试试。首先我们复制一份lwip_tcpecho代码,重命名为lwip_tcpecho_RGMII,如下图所示。

Silas1750的博客 927

帕德伯恩大学轴承数据集(PU)介绍

PU数据集介绍一、帕德伯恩大学轴承数据集故障类别说明二、关于损伤描述2.1 损伤组合:2.2 重复和多重损伤的安排:2.3 几何尺寸2.4 损伤程度2.5损伤特征数据集损伤类别三、人为损坏轴承3.1 最常用的人为损伤制造方法是:3.2 本数据集使用的人工损坏是由三种不同方法引起的四、通过加速寿命试验产生真正的轴承损坏样本 一、帕德伯恩大学轴承数据集 数据集下载地址 从帕德伯恩大学获得的PU数据集是一个6203轴承数据集,包括人为诱发的和真实的损害。采用压电加速度计采集轴承座的振动信号,采样频率为64 kHz

m0_47180208的博客 3万+

《Mastering Delphi6》学习笔记之三

 代码编辑器/窗体设计器/Object Inspector中的一些快捷键在代码编辑器中按Ctrl+E可以 激活Increment Search。这样就避免了从菜单中选择Search->Find,再输入文本的繁琐步骤。选中一或者几行文本,然后按Ctrl+Shift+I,可以增加这几行的缩进量;Ctrl+Shift+U减少缩进。缩进的距离取决于Editor Options里面的Auto I

weizhisheng的专栏 1258

SAP生产版本导入避坑大全:从‘黄灯’到‘绿灯’,详解CM_FV_MKAL_CONSISTENCY_CHECK检查函数

本文深入解析SAP生产版本导入过程中的常见问题,特别是通过`CM_FV_MKAL_CONSISTENCY_CHECK`检查函数从‘黄灯’异常到‘绿灯’正常的修复方法。涵盖静态与动态校验机制、典型异常场景诊断及批量导入最佳实践,帮助SAP运维人员高效解决生产版本管理难题。

weixin_30568591的博客 398

《Mastering Delphi 6》学习笔记之七

《Mastering Delphi 6》 学习笔记之七 TObject中的ClassParent是一个很让人感兴趣的方法。通过这个方法,你可以从某个类开始,层层上溯,一直到整个VCL的根TObject为止,描述出一个完整的层次列表。可以用下面的例子来检查类继承关系:procedure TForm1.Button1Click(Sender: TObject);var  CurrO

weizhisheng的专栏 1082

Zemax显微镜设计:从物镜到目镜的完整光学系统优化

本文详细介绍了使用Zemax进行显微镜光学系统设计的完整流程,从物镜到目镜的优化技巧。通过实战案例和关键参数设置,帮助读者掌握数值孔径、视场角等核心概念,实现高分辨率显微镜设计。文章特别强调了系统级优化和公差分析的重要性,为科研和工业检测提供可靠的光学解决方案。

weixin_42549451的博客 447

98DX3236内核编译过程小结

0.条件(1)Marvell技术支持提供的压缩文件:GNU EABI:arm-mv5sft-linux-gnueabi_SW3.2.tar.bz2.tar.bz2armebv7-marvell-linux-gnueabi-softfp_i686_201201.tar.bz2CPSS代码:Cpss-PP-DxCh-4.2_012.zipLinux内核文件:lsp-4.2_012.zipLSP-Uni...

snaking616 1810

《Mastering Delphi 6》学习笔记之五

《Mastering Delphi 6》 学习笔记之五 在某个类中用protected声明的变量,在本单元之外是不能够随意访问的(通过声明子类才可以访问其protected域)。《Mastering Delphi 6》中提到了一个不常用的技巧:// Unit2type TTest = class  protected   protectedVar : integer;e

weizhisheng的专栏 1124

最新Python爬虫实战(入门爬虫篇)——案例20:某股票数据采集(详细爬虫思路截图+抓包动图演示+完整爬虫代码+详细注释)

本次案例针对某股票行情网的静态HTML页面,实现了全市场股票数据的全自动化爬取,覆盖了从抓包分析、请求模拟、数据解析到数据存储的完整爬虫流程,非常适合入门学习者巩固基础,核心知识点和实现要点总结如下:首先是页面分析的核心逻辑,静态HTML页面的数据爬取,核心在于通过浏览器开发者工具,完成完整的抓包分析和标签结构定位。我们不需要像动态页面那样找隐藏的API接口,只需要确认数据在主文档的HTML源码中,然后通过元素选择器,精准找到每个字段对应的标签,总结出统一的标签结构规律,就能实现批量数据提取。

努力让自己发光,对的人才能迎着光而来 19万+

《Mastering Delphi 6》学习笔记之八

构件自动清除的内幕 我们已经知道,TComponent在释放自身的时候会自动删除它Owns的所有Component,这是Delphi程序的一个极大特点。否则的话,任何动态生成的对象比如Menu Items都要自己维护和删除,那将是多么痛苦。VCL是如何做到这一点的呢?可以想象到,每个Component内部应该保持一个列表,记录它所拥有的Components,在自身的析构函数中将列表中的所有

weizhisheng的专栏 1342

Qt入门教程【Core篇】singal and slot信号与槽

Qt中信号与槽singal and slot

小鱼酱的博客 2455

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

《Mastering Delphi 6》学习笔记之四 (转)

《Mastering Delphi 6》学习笔记之四 (转)[@more@] ...

csd3176的博客 91

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

《Mastering Delphi 6》学习笔记之九

无名称构件的使用 我曾在许多Delphi资料中看到这样的说法:每一个Component都必须有一个不为空的Name,用于和其他Component相区分。过去我也对这种说法深信不疑。但是看过《Mastering Delphi 6》后,我知道我错了。Component的Name属性可以是空的,特别是对于Menu Separator,Static Label,Bevel,Shape和Panel等

weizhisheng的专栏 1184

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

《Mastering Delphi 6学习笔记》之二 (转)

《Mastering Delphi 6学习笔记》之二 (转)[@more@] 《Mastering Delphi 6学习笔记》之二 XML:namespace prefix = o ns = "urn:schemas-...

cuiji1279的博客 177

《Mastering Delphi6》学习笔记之三 (转)

《Mastering Delphi6》学习笔记之三 (转)[@more@] 代码编辑器/窗体设计器/object Inspector中的一些快捷键 在代码编辑器中按Ctrl+E可以 激活Increment Search。...

cuiji1279的博客 156
上一篇: 《Mastering Delphi 6》学习笔记之五
下一篇: 《Mastering Delphi 6》学习笔记之七
weizhisheng
博客等级 码龄26年 2粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值