如何枚举DComconnection的ProviderName?(20分)

  • 主题发起人 hexenzhou
  • 开始时间
H

hexenzhou

Unregistered / Unconfirmed
GUEST, unregistred user!
在IDE 设计期,通过单击DComconnetion的ServerName属性可以得到本机或网络上所有服务器的
ProgId,请问有什么方法可以在程序运行时动态的得到服务器的ProgId呢?
 
procedure TForm1.Button1Click(Sender: TObject);
var
V:OleVariant;
I:Integer;
begin
V:=Conn.GetServerList;
for I:=VarArrayLowBound(V,1) to VarArrayHighBound(V,1)do
ListBox1.Items.Add(V);
end;
//Conn為SocketConnection,
//DcomConnection沒有提供這個方法.
 
TDCOMConnection的繼承關系為:
TDCOMConnction-->TCOMConnection-->TDispatchConnection
在TDispatchConnection中有一個GetServerList私有方法.因此可以重新聲明一個類,
將GetServerList方法引出,以供調用.
unit MyConnection
interface
uses
MConnect;
type
TMyConn=Class(TDispatchConnection)
public function MyGetServerList:OleVariant;
end;

implementation
{ TMyConn }
function TMyConn.MyGetServerList: OleVariant;
begin
Result:=GetServerList;
end;

//使用:
procedure TForm1.Button1Click(Sender: TObject);
var
V:OleVariant;
I:Integer;
begin
V:=TMyConn(DComConnection1).MyGetServerList;
for I:=VarArrayLowBound(V,1) to VarArrayHighBound(V,1)do
ListBox1.Items.Add(V);
end;
 
谢谢somkingroom兄的回答,希望以后可以在com/dcom/com+方面多多指教。
 

Similar threads

顶部