下面的过程可以在ListBox中列出SQL Server服务器列表,别忘了引用Comobj单元。
procedure GetSQLServerList;
var
SQLServer:Variant;
SQLServerList:Variant;
i,nServers:Integer;
sRatvalue:string;
begin
SQLServer:=CreateOLEObject('SQLDMO.Application');
SQLServerList:=SQLServer.ListAvailableSQLServers;
nServers:=SQLServerList.Count;
for i:=1 to nServers do
ListBox1.Items.Add(SQLServerList.Item(i));
SQLServer:=null;
SQLServerList:=null;
end;