delphi传递与复制对象(DELPHI5从入门到精通75页)

本文介绍了在Delphi中如何传递和复制对象。通过示例代码展示了如何使用`Application.CreateForm`创建对象的副本,以及如何根据组件类型动态创建新对象。重点在于理解对象引用和内存中的实际对象。
摘要由CSDN通过智能技术生成

var
Button2:Tbutton;
begin
Button2 := button1;
这段代码没有建立一个新对象,而是建立了对内存中同一个对象的引用。内存中只有1个对象,而Button1,Button2变量都引用它。如果将对象作为参数传递给函数也是一样,没有建立新对象,而是在代码的两个不同位置引用了同一个对象。

我们可以查询组件的类(sender.classtype),然后使用类引用建立该类型的新对象。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;

type
TForm1 = class(TForm)
Button1: TButton;
ScrollBox1: TScrollBox;
Label1: TLabel;
CheckBox1: TCheckBox;
Label2: TLabel;
Button2: TButton;
Edit1: TEdit;
BitBtn1: TBitBtn;
SpeedButton1: TSpeedButton;
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure ClickComp(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值