---
title: "4个关联library的方法"
author: "dandada"
date: "2014-12-23T11:00:35Z"
tags: []
slug: "4-library"
draft: false
lastmod: "2014-12-23T11:00:35Z"
id: 2169453
url: "https://dandada.iteye.com/blog/2169453"
---

1) By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
2) By using Automation Object Model (AOM).
3) By using ExecuteFile method.
4) using LoadFunctionLibrary method.

ExecuteFile是最慢而且有时候不稳定,基本可以用LoadFunctionLibrary来代替.

第二种方法在编写框架的时候非常有用,比如我的框架就使使用如下代码关联一个用户指定文件夹下的所有library,动态又高效.


```java

If TAFQTPLibraryPath <> "" Then
                Dim TAFCoreLibraries() As String = Directory.GetFiles(TAFQTPLibraryPath)
                For Each CoreLib As String In TAFCoreLibraries
                    If CoreLib.EndsWith(".vbs") Then
                        qtApp.Test.Settings.Resources.Libraries.Add(CoreLib)
                    End If
                Next
End If

```