コード補完の取得


alond  2005-09-05 19:12:14  No: 17406  IP: 192.*.*.*

はじめまして!!

助けて頂きたいのですが、
コード補完で出てくる
「プロパティー」「function」「型」をmemoに抜き出す方法は有るでしょうか?

もし、ありましたら教えて頂けますと助かります。
よろしくおねがいいたします。

編集 削除
RAN  2005-09-08 11:20:00  No: 17407  IP: 192.*.*.*

Delphi7以上ならIOTACodeInsightManagerでSymbolListを取得すれば
良いと思います。以下は手抜きですが、だいたいこんな感じだと思います。
パッケージを作ってインストールすれば、ショートカットCtrl+Bで起動します。

unit TestUnit;

interface
uses
  ToolsAPI, Classes;

type
  TSampleBufferList = class(TNotifierObject, IOTAKeyboardBinding)
  private
    procedure BufferListProc(const Context: IOTAKeyContext; KeyCode: TShortCut;
      var BindingResult: TKeyBindingResult);
  public
    function GetBindingType: TBindingType;
    function GetDisplayName: string;
    function GetName: string;
    procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
  end;

procedure Register;
procedure UnRegister;

implementation
uses
  Menus, Dialogs, SysUtils;

var
  BindNo: integer;

procedure Register;
begin
  BindNo := (BorlandIDEServices as IOTAKeyBoardServices).AddKeyboardBinding(TSampleBufferList.Create);
end;

procedure UnRegister;
begin
  (BorlandIDEServices as IOTAKeyBoardServices).RemoveKeyboardBinding(BindNo);
end;

{ TSampleBufferList }

procedure TSampleBufferList.BindKeyboard(
  const BindingServices: IOTAKeyBindingServices);
begin
  BindingServices.AddKeyBinding([ShortCut(Ord('B'), [ssCtrl])],
    BufferListProc, nil);
end;

procedure TSampleBufferList.BufferListProc(const Context: IOTAKeyContext;
  KeyCode: TShortCut; var BindingResult: TKeyBindingResult);
var
  CodeInsightServices: IOTACodeInsightServices;
  CodeInsightManager: IOTACodeInsightManager;
  SymbolList: IOTACodeInsightSymbolList;
  UserInput: string;
  Allow: boolean;
  i: integer;

begin

  if Supports(BorlandIDEServices, IOTACodeInsightServices, CodeInsightServices) then
  begin
    if CodeInsightServices.CodeInsightManagerCount > 0 then
      CodeInsightManager := CodeInsightServices.CodeInsightManager[(CodeInsightServices.CodeInsightManagerCount -1)];

    if not (CodeInsightManager = nil) then
    begin
      CodeInsightServices.SetQueryContext(Context.EditBuffer.TopView, CodeInsightManager);

      Allow := True;
      CodeInsightManager.AllowCodeInsight(Allow, #0);
      if not Allow then
        exit;

      UserInput := '';
      if not CodeInsightManager.InvokeCodeCompletion(itManual, UserInput) then
        exit;

      CodeInsightManager.GetSymbolList(SymbolList);
      if SymbolList = nil then
        exit;

      for i := 0 to 10 do
        showMessage(SymbolList.SymbolText[i]);
    end;
  end;

  BindingResult := krHandled;
end;

function TSampleBufferList.GetBindingType: TBindingType;
begin
  Result := btPartial;
end;

function TSampleBufferList.GetDisplayName: string;
begin
  Result := 'テスト';
end;

function TSampleBufferList.GetName: string;
begin
  Result := 'Test.BufferList';
end;

initialization

finalization
  UnRegister;

end.

編集 削除
RAN  2005-09-08 11:43:35  No: 17408  IP: 192.*.*.*

詳しくはOpenToolsAPIのヘルプをご覧ください。
GExpertsのGX_KibitzCompユニットも参考になりそうです。

編集 削除
RAN  2005-09-08 13:49:47  No: 17409  IP: 192.*.*.*

CodeInsightServices.SetQueryContext(nil, nil);
を忘れてました。

処理の最後に(for文のshowMessageの下に)追加してください。

編集 削除