在自动化的过程中,经常需要对两个对象(或属性)进行比较,看否前后一致,来判断某个对象是否被修改过,而在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;
注,以上脚本都很简短,是因为对象做了别名映射。