在TC中,提供了一个Regions对象集合,专门管理图像对象,可以通过以下方法添加图像对象到Regions集合中:
//添加图像方式:
//1.Add images from the Regions editor
//2.Add images from the Project Explorer
//3.Add images from the Image Viewer
//4.Add images during recording
//5.Add images from scrīpts
Regions对象封装了几个常用的方法,如Regions.AddPicture(添加图像)、Regions.GetPicture(获取图像)、Regions.FindRegion(查找图像)、Picture.Find(查找图像)等,具体使用如下:
//在脚本中添加图像
procedure AddImageFromscrīpt;
begin
//添加主窗体图像
Regions.AddPicture(Aliases.TCSampleForm,'TCSampleForm');
//添加主窗体中操作数1的图像
Regions.AddPicture(Aliases.TCSampleOperand1,'TCSampleOperand1');
end;
//回放脚本过程中截取图像与在Regions集合中的图像进行比较
procedure CompareImage_Playback;
begin
if not Regions.Compare('TCSampleFormChangeName', Aliases.TCSampleForm) then
Log.Error('The compared regions are not identical.', Aliases.TCSampleForm.Name);
end;
//Regions集合中两个图像进行比较
procedure CompareImage_Regions;
begin
if not Regions.Compare('TCSampleFormChangeName', 'TCSampleForm') then
Log.Error('The compared regions are not identical.', 'TCSampleForm');
end;
//使用Picture对象比较两个图像
procedure CompareImage_Picture;
var pict1,pict2 : olevariant;
begin
pict1 := Regions.GetPicture('TCSampleForm');
pict2 := Regions.GetPicture('TCSampleFormChangeName');来源 www.pms.cc
if not pict1.Compare(pict2) then
Log.Error('The compared regions are not identical.');
end;
//使用Regions对象的FindRegion方法查找图像
procedure FindImage_Regions;
var pict1,pict2 : olevariant;
begin
if (Regions.FindRegion('TCSampleOperand1','TCSampleForm') = nil) then
Log.Warning('Picture not found.');
end;
//使用Picture对象的Find方法查找图像
procedure FindImage_Picture;
var pict1,pict2 : olevariant;
begin
pict1 := Regions.GetPicture('TCSampleForm');
pict2 := Regions.GetPicture('TCSampleOperand1');
if (pict1.Find(pict2) = nil) then
Log.Warning('Picture not found.');
end;