TC中如何新增物件及比較物件

hezerong發表於2008-05-02

在自動化的過程中,經常需要對兩個物件(或屬性)進行比較,看否前後一致,來判斷某個物件是否被修改過,而在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;

注,以上指令碼都很簡短,是因為物件做了別名對映。

 

相關文章