TC中如何添加对象及比较对象

在自动化的过程中,经常需要对两个对象(或属性)进行比较,看否前后一致,来判断某个对象是否被修改过,而在TC中就提供了这样的方法:Objects.Compare(Object1,Object2)

首先,我们要添加两个对象,可以在脚本录制或回放过程添加,也可以在这之前添加,通过以下方法可以添加对象:

//添加对象属性方式
//1.Adding property collections from the Object Browser
//2.Adding property collections from the Object Properties window
//3.Adding property collections from the Tools toolbar
//4.Adding property collections during recording
//5.Adding property collections from scrīpts
//6.Adding property collections from the Objects editor
//7.Adding property collections from the Project Explorer

接下来就是如何比较了,这些方法具体使用如下:

//在脚本中添加对象属性
procedure AddObjectfromscrīpt;
var
  w, PropertyNames, CollectionName : OleVariant;
begin
  //
激活窗体
  Aliases.TCSampleForm.Activate;
  //
保存当前激活的窗体对象
  w := Sys.Desktop.ActiveWindow();
  //
设置将要保存的属性名称
  
  PropertyNames := 'WndCaption';
  //
设置在Object集合中保存的名称

  CollectionName := 'TCSampleFormName';
  //
保存激活窗体对象属性
  Objects.Save(w, CollectionName,PropertyNames);
end;

//比较操作数1的对象属性名称是否改变
procedure CompareOperend1;
begin
  if not Objects.Compare(Aliases.TCSampleOperand1, 'TCSampleOperand1') then
    showmessage('Objects are not identical.'+Objects.LastError)
else showmessage('Objects are identical.');
end;

注,以上脚本都很简短,是因为对象做了别名映射。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值