delphi中 注意一点,record 类型 参数默认是 值拷贝,class 参数 默认是传地址;值传递,指针传递、引用传递
作为函数的入参,若是record类型,默认是值拷贝,效率低,若要传指针,需要加 var ;
作为函数的入参,若是 class类型,默认是传地址,不需要加var



unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TDataWarp = class
a: Integer;
b: Integer;
end; TForm1 = class(TForm)
Button1: TButton;
mmo1: TMemo;
procedure swap2(Sender: TObject; dw: TDataWarp);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction); private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ReportMemoryLeaksOnShutdown := True;
end; procedure TForm1.swap2(Sender: TObject; dw: TDataWarp);
var
tmp: Integer;
begin
tmp := dw.a;
dw.a := dw.b;
dw.b := tmp; mmo1.Lines.Add(dw.a.ToString); dw := nil;
dw.Free; end; procedure TForm1.Button1Click(Sender: TObject);
var
dw: TDataWarp;
begin
dw := TDataWarp.Create;
dw.a := 6;
dw.b := 9;
swap2(Sender, dw);
mmo1.Lines.Add(dw.a.ToString);
dw.Free; end; end.
delphi中 注意一点,record 类型 参数默认是 值拷贝,class 参数 默认是传地址;值传递,指针传递、引用传递的更多相关文章
- delphi中move函数的正确理解(const和var一样,都是传地址,所以Move是传地址,而恰恰不是传值)太精彩了 good
我们能看到以下代码var pSource,pDest:PChar; len: integer;.......................//一些代码Move(pSource,pDest,l ...
- Delphi中BCD和Currency类型
用了这些年的Delphi,竟然对Currency及TBCDField一知半解,下文给了很好的讲解,值得一读. 一. BCD类型 BCD即Binary-Coded Decimal?,在Del ...
- java方法中只有值传递,没有引用传递
public class Example { String testString = new String("good"); char[] testCharArray = {'a' ...
- 【Java基础】11、java方法中只有值传递,没有引用传递
public class Example { String testString = new String("good"); char[] testCharArray = {'a' ...
- delphi中的各种文件类型介绍【转】
1.DPR: Delphi Project文件,包含了Pascal代码.应用系统的工程文件2.PAS: Pascal文件,Pascal单元的源代码,可以是与窗体有关的单元或是独立的单元.3.DFM:D ...
- delphi中的各种文件类型介绍
1.DPR: Delphi Project文件,包含了Pascal代码.应用系统的工程文件2.PAS: Pascal文件,Pascal单元的源代码,可以是与窗体有关的单元或是独立的单元.3.DFM:D ...
- delphi中如何将string类型的字符串数据转化成byte[]字节数组类型的数据
var S:String; P:PChar; B:array of Byte;begin S:='Hello'; SetLength(B,Length(S)+1); P:=PChar(S) ...
- oralce 存储过程传入 record 类型的参数?
先定义一个 package , package中含有一个 record 类型的变量 create or replace package pkg_record is type emp_record is ...
- Delphi 中 COM 实现研究手记(一)
前言 前些日子用 Delphi 写了一个 Windows 外壳扩展程序,大家知道 Windows 外壳扩展实际上就是 COM 的一种应用 -- Shell COM,虽然整个程序写得还算比较顺利,但写完 ...
- Delphi中的关键字与保留字
Delphi中的关键字与保留字 分类整理 Delphi 中的“关键字”和“保留字”,方便查询 感谢原作者的收集整理! 关键字和保留字的区别在于,关键字不推荐作标示符(编译器已经内置相关函数或者留给保留 ...
随机推荐
- Linux一键安装docker脚本,含ubuntu和centos
将脚本保存为docker_install.sh,可以上传git,到服务器中,git clone下来后,sh docker_install.sh即可自动安装 ubuntu实现 # 以Ubuntu为例 # ...
- java进阶(32)--Collections工具类
一.简介:Collection与Collections区别 1.Java.until.Collection是集合接口 2.Java.until.Collections是集合工具类,方便集合的操作 二. ...
- Angular系列教程之路由守卫
.markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...
- phpcms : Uncaught Error: [] operator not supported for strings... 的解决方案
打开/phpcms/modules/admin/classes/push_api.class.php,大概在约 141行, $fields_arr = $fields_value = ''; 将它改为 ...
- 海思Hi35xx 通过uboot 读取U盘文件进行固件升级
前言 基本过程为:uboot 启动后,通过命令将U盘的的文件读取到内存中,再通过uboot 的flash 写入命令将读取到内存中的升级文件写入到flash的固定位置. (一)usb常用命令 uboot ...
- [转帖]数据库Ingres、Oracle、PostgreSQL、MySQL的历史总结
http://www.codeforest.cn/article/192# Ingres 1973年,加州大学伯克利分校的Michael Stonebraker和EugeneWong,从Edgar F ...
- TiKV 服务部署的注意事项
TiKV 服务部署的注意事项 背景 最近发现tikv总是会掉线 不知道是哪里触发了啥样子的bug. 所以想着使用systemd 管理一下, 至少在tikv宕机的时候能够拉起来服务. 二进制文件 pd- ...
- [转帖]关于kafka压力测试(使用官方自带脚本测试)
文章目录 kafka官方自带压测脚本文件 Producer生产者环境测试 测试命令 返回测试结果 Consumer消费者环境测试 测试命令 测试结果说明 提升kafka的吞吐量 可通过以下的方式来提升 ...
- [转帖]python中对配置文件的读写操作
https://juejin.cn/post/6844903586963390471 python内置的configparser模块能非常方便的对配置文件进行操作,常见的配置文件有*.ini和*.co ...
- [转帖]Linux开发环境——SCL软件集
一.SCL简介 1.SCL简介 SCL(Software Collections)是一个CentOS/RHEL Linux平台的软件多版本共存解决方案,为RHEL/CentOS Linux用户提供一 ...