开发者

How can I get all installed components inside IDE? (Delphi)

开发者 https://www.devze.com 2022-12-08 20:33 出处:网络
How can I get all installed components in TStrings? 开发者_如何学Go I think this code work only within packages:

How can I get all installed components in TStrings?

开发者_如何学Go

I think this code work only within packages:

    uses TypInfo, ToolIntf, Exptintf;

procedure GetComponentNames(lst: TStrings);
var
  i, k: Integer;
  CRef: TClass;
  strName: ShortString;
begin
  lst.Clear;
  for i := 0 to ToolServices.GetModuleCount-1 do
  begin
    for k := 0 to ToolServices.GetComponentCount(i)-1 do
      begin
       CRef := TClass(GetClass(ToolServices.GetComponentName(i, k)));
       while CRef <> nil do
       begin
         strName := CRef.ClassName;
         if lst.IndexOf(strName) = -1 then
           lst.Add(strName);
         if str <> 'TComponent' then
          CRef := CRef.ClassParent
         else
           CRef := nil;
       end;
      end;
  end;    
end;

Or:

uses ToolsApi;

{....}

var
  a, i: Integer;
begin
  with (BorlandIDEServices as IOTAPackageServices) do
  begin
    for a := 0 to GetPackageCount - 1 do
    begin
      for i := 0 to GetComponentCount(a) - 1 do
      begin
        {get each component name with GetComponentName(a, i);}
        // DoSomething   
      end;
    end;
  end;
end;

Thanks for help.


This example doesn't use the OpenAPI, it uses the Registry. It works but it also lists non-visual components amongst other hidden items.

procedure GetComponentNames(lst: TStrings);
var
  i, j, iPos: Integer;
  Reg: TRegistry;
  sComponent: String;
  slValues, slData: TStrings;
begin
  Reg := TRegistry.Create;
  slValues := TStringList.Create;
  slData := TStringList.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    Reg.OpenKey('Software\Borland\Delphi\6.0\Palette', False); // Change reg key where appropriate
    Reg.GetValueNames(slValues);
    for i := 0 to Pred(slValues.Count) do
    begin
      lst.Append(slValues[i]);
      lst.Append('----------');
      slData.Delimiter := ';';
      slData.DelimitedText := Reg.ReadString(slValues[i]);
      for j := 0 to Pred(slData.Count) do
      begin
        sComponent := slData[j];
        iPos := Pos('.', sComponent);
        if (iPos > 0) then
          Delete(sComponent, 1, iPos);
        lst.Append(sComponent);
      end;
    end;
  finally
    slData.Free;
    slValues.Free;
    Reg.Free;
  end; {try..finally}
end;

I'm not saying this is ideal but it does give you a list and a headstart.

0

精彩评论

暂无评论...
验证码 换一张
取 消