当前位置:网站首页>Delphi中的冷门知识点
Delphi中的冷门知识点
2022-06-10 10:01:00 【南通DXZ】
前言
平时使用Delphi编程的过程中,经常会有一些模棱两可的概念,似懂非懂。有的冷门知识当时通过搜索引擎获取学会了,可用不了几个月又全忘光,第二次出现又得重新学习。这里对平时遇到的冷门知识点做一个记录汇总,方便日后查看。
1、assert函数的用法
函数原型:procedure Assert(expr : Boolean [; const msg: string]);
函数作用:用来进行条件测试
使用方法:参数如果为True,没有任何反应。如果为False,就会报错,如下图

当然,它是一个重载函数,第二个参数是可以自定义的。
2、回车符与换行符
编程的时候经常遇到需要处理回车符与换行符,回车符可以用Chr(13)或者#13表示,换行符同理Chr(10),示例代码:
// JvInterpreterProgram1.Source := 'begin' + Chr(13) +
// 'result := ' + Edit1.Text + ';' + Chr(13) +
// 'end;';
JvInterpreterProgram1.Source :=
'begin' + #13 +
'result := ' + Edit1.Text + ';' + #13 +
'end;';
3、Sender关键字的妙用
看下面一个点击按钮事件代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
end;
现在有button2和button3同时使用Button1的按钮事件,Sender就可以很好的区分是哪个按钮点击过来的.
procedure TForm1.Button1Click(Sender: TObject);
begin
if Sender = Button1 then ShowMessage('Button1');
if Sender = Button2 then ShowMessage('Button2');
if Sender = Button3 then ShowMessage('Button3');
end;
4、nil、Assigned的用法通俗讲解
上述的几个关键字容易混淆,对于初学者用法也不容易讲解,这里结合汇编来讲解,讲一次一辈子都不会忘记。
nil:字面解释nil:空指针,空地址,对象也是指针,可以object := nil;
看下面一段代码
procedure TForm1.Button1Click(Sender: TObject);
var
p: Pointer;
Value: integer;
begin
Value := $365;
p := @Value;
p := @p;
p := 0;
if Assigned(p) then
ShowMessage('被定义了(Assigned)');
if p = nil then
ShowMessage('未被定义了(nil)');
end;
我们知道在内存中
每一个变量、数值、指针等都会有一个地址
只有通过这个地址才能操作他们。
举例:
0x0018F57C==>>0x00000000中
0018F57C是地址,00000000就是值
要想修改值,知道地址就可以了
就像一个住址对应一套房子,装修工人要装修房子只要知道住址就能找到房子去装修。
Value := $365;
语句执行完成之后
从
0x0018F57C==>>0x00000000
到
0x0018F57C==>>0x00000365
0x00000000值被修改为0x00000365
我们可以这样理解值就是Value,而该值的地址就是0x0018F57C
p := @Value;
语句执行完成之后
从
0x0018F580==>>0x00000000
到
0x0018F580==>>0x0018F57C
0x00000000值被修改为0x0018F57C
p是指针,本身也是值,他也有自己的地址,0x0018F580就是他的地址。
@Value就是取Value的地址赋值给p,
所以也就顺理成章的把@Value的地址0x0018F57C写入到内存中。
我们可以这样理解值就是p,而该值的地址就是0x0018F580
p := @p;
不相信我们可以再次尝试,取指针的p的地址赋值给p会怎样?
按照上面逻辑p的地址为0x0018F580,执行完成之后应该
0x0018F580==>>0x0018F580
地址与值应该一样。
去调试器中跟踪,发行与我们设想一致。
那么要想p成为空指针,只需要
0x0018F580==>>0x0000000 值为0即可
通过编程语句
p := nil;
//或者,等同效果,建议还是使用nil
p := 0;
那么我们要判断指针p是不是空指针,只需要判断
0x0018F580==>>0x0000000 的值是否为0
简单说就是判断p是不是0
这里p是指针
我们不能简单写语句 if p=0 then 编译器通不过
通过编程语句
if Assigned(p) then
//或者
if p <> nil then
写了这么多,希望能各位能理解nil的底层逻辑。
边栏推荐
- osg基本操作
- Dr. jiangxiaowei, a member of hpca Hall of fame, is the chief scientist of Dayu smart core
- Neo 黑客松获奖名单揭晓,上万美金花落谁家?
- 【边缘检测】基于matlab八方向sobel图像边缘检测【含Matlab源码 1865期】
- "Nonsense" database primary key design
- Google Earth Engine(GEE)——GPWv411:平均行政单位面积数据集
- phpstrom 将项目上传码云
- “隔离险”成“网红”产品,不少投保者却表示:理赔难
- Radiolisttile is displayed in row of the shutter
- Important technological breakthrough in privacy computing! 100 million level data density analysis can be completed in 10 minutes
猜你喜欢

一个独特的简历生成器,开源了!

ADB 日志抓取

In 2025, the output value, added value and other scale indicators of the construction industry will continue to remain at the forefront of the country

Xcode8.3.2 自动打包脚本

Bing's website search site: < domain name>< search content>
![[essay for college entrance examination season] I have something to say about the college entrance examination](/img/d0/2be5a0d540f443e965be7761266a89.png)
[essay for college entrance examination season] I have something to say about the college entrance examination

Important technological breakthrough in privacy computing! 100 million level data density analysis can be completed in 10 minutes

Design of smart home control system (onenet) based on stm32_ two thousand and twenty-two

2021 ciscn-pwn 初赛

selenium分布式测试
随机推荐
HMM details + examples
[image feature extraction] image feature extraction based on MATLAB pulse coupled neural network (PCNN) [including Matlab source code 1868]
Example 3 of lambda expression
618 is coming. Is it too time-consuming to generate a large number of coupons? Threadpooltaskexecutor thread pool helps you
一行代码制作数据分析交叉表,太便捷了
"Pit" of mongoreplay
张小白教你使用OGG实现Oracle 19C到MySQL 5.7的数据同步(1)
What are the tools and software needed for SCM development
ADB 日志抓取
Use nsenter to enter netns to capture packets
2022年金属非金属矿山提升机操作考试题库及答案
成都测试设备定制_单片机C语言之数据类型初步介绍
2022年普通脚手架工(建筑特殊工种)操作证考试题库及模拟考试
Important technological breakthrough in privacy computing! 100 million level data density analysis can be completed in 10 minutes
[497. random points in non overlapping rectangles]
In 2025, the output value, added value and other scale indicators of the construction industry will continue to remain at the forefront of the country
phpstrom 將項目上傳碼雲
威纶通触摸屏直接与台达变频器进行MODBUS RTU通信的具体方法(图文)
Radiolisttile is displayed in row of the shutter
[Blue Bridge Cup training 100 questions] scratch apple is ripe blue bridge cup scratch competition special prediction programming question intensive training simulation exercise question 13