⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmmain.pas

📁 多数代码可以直接在Delphi6和Delphi7环境下运行。部分涉及.NET技术内容的代码
💻 PAS
字号:
unit fmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, OleServer, CmAdmCtl, COMAdmin, ComObj;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    ListBox2: TListBox;
    BitBtn1: TBitBtn;
    Button2: TButton;
    COMAdminCatalog1: TCOMAdminCatalog;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
    adminIntf : ICOMAdminCatalog;
    acoll : ICatalogCollection;
    anItem : ICatalogObject;
  protected
    procedure GetCatalogByCoAdmin(const sName : String; var aCol : TCOMAdminCatalogCollection; var aObj : TCOMAdminCatalogObject);
    procedure GetCollection;
    procedure GetAdminInterface;
    procedure GetCatalogByName(const sName : String);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  iCount : Integer;
begin
  GetAdminInterface;
  try
    GetCollection;
    for iCount := 0 to acoll.Count -1 do
    begin
      anItem := acoll.Item[iCount] as ICatalogObject;
      ListBox1.Items.Add(anItem.Name);
    end;
  finally // wrap up
    anItem := nil;
    acoll := nil;
    adminIntf := nil;
  end;    // try/finally
end;

procedure TForm1.GetCatalogByName(const sName : String);
var
  iCount : Integer;
begin
  GetAdminInterface;
  GetCollection;
  for iCount := 0 to acoll.Count - 1 do
  begin
    anItem := acoll.Item[iCount] as ICatalogObject;
    if (anItem.Name = sName) then
    begin
      exit;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  iCount : Integer;
  aCollection : ICatalogCollection;
  aCmp : ICatalogObject;
begin
  ListBox2.Items.Clear;
  if (ListBox1.ItemIndex = -1) then
    exit;

  GetCatalogByName(ListBox1.Items[ListBox1.ItemIndex]);
  aCollection := acoll.GetCollection('Components', anItem.Key) as ICatalogCollection;
  if (aCollection <> nil) then
  begin
    aCollection.Populate;
    try
      for iCount := 0 to aCollection.Count - 1 do    // Iterate
      begin
        aCmp := aCollection.Item[iCount] as ICatalogObject;
        ListBox2.Items.Add(aCmp.Name);
        aCmp := nil;
      end;    // for
    finally // wrap up
      aCollection := nil;
      anItem := nil;
      acoll := nil;
      adminIntf := nil;
    end;    // try/finally
  end;
end;

procedure TForm1.GetAdminInterface;
begin
  adminIntf := CreateComObject(CLASS_COMAdminCatalog) as ICOMAdminCatalog;
end;

procedure TForm1.GetCollection;
begin
  acoll := adminIntf.GetCollection('Applications') as ICatalogCollection;
  acoll.Populate;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  aCollection : TCOMAdminCatalogCollection;
  iCount : Integer;
  aObj : TCOMAdminCatalogObject;
begin
  aCollection := Self.COMAdminCatalog1.GetCollection('Applications');

  try
    aCollection.Populate;
    for iCount := 0 to aCollection.Count - 1 do    // Iterate
    begin
      aObj := aCollection.Get_Item(iCount);
      ListBox1.Items.Add(aObj.Name);
      FreeAndNil(aObj);
    end;    // for
  finally
    FreeAndNil(aCollection);
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  aCollection : TCOMAdminCatalogCollection;
  aCmpCol : TCOMAdminCatalogCollection;
  aCmp : TCOMAdminCatalogObject;
  iCount : Integer;
  aObj : TCOMAdminCatalogObject;
begin
  ListBox2.Items.Clear;
  if (ListBox1.ItemIndex = -1) then
    exit;
  GetCatalogByCoAdmin(ListBox1.Items[ListBox1.ItemIndex], aCollection, aObj);
  aCmpCol := aCollection.GetCollection('Components', aObj.Get_Key);
  if (aCmpCol <> nil) then
  begin
    aCmpCol.Populate;
    try
      for iCount := 0 to aCmpCol.Count - 1 do    // Iterate
      begin
        aCmp := aCmpCol.Get_Item(iCount);
        ListBox2.Items.Add(aCmp.Name);
        FreeAndNil(aCmp);
      end;    // for
    finally // wrap up
      FreeAndNil(aCmpCol);
      FreeAndNil(aObj);
      FreeAndNil(aCollection);
    end;    // try/finally
  end;
end;

procedure TForm1.GetCatalogByCoAdmin(const sName : String; var aCol : TCOMAdminCatalogCollection; var aObj : TCOMAdminCatalogObject);
var
  iCount : Integer;
begin
  aCol := Self.COMAdminCatalog1.GetCollection('Applications');
  aCol.Populate;
  for iCount := 0 to aCol.Count - 1 do
  begin
    aObj := aCol.Get_Item(iCount);
    if (aObj.Name = sName) then
      exit
    else
      FreeAndNil(aObj);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -