有那位知道Code Insight是如何实现的,给个思路也成
就如在DELPHI里的那样功能
望各位大侠不吝赐教,先谢了^_^

解决方案 »

  1.   

    应该是通过Open Tools API编程,
    生成相应的包,在IDE中使用。
    就像Wizard或者叫Expert那样!
    这方面的资料不太多,我也不太精
    只看过一本有相关介绍的书 《Delphi6应用开发指南》——清华大学出版社出版的
    可以到Google上搜搜,国外有些站点会多些介绍(我的e文太p了!)
    还听说了一本李维翻译的,好像叫《Delphi3.x奥秘》之类的有介绍,就是没找到!多多交流:)
      

  2.   

    后一本偶没搜到
    前一本偶DOWN下来它跟偶说解压要密码,晕
    那位能给介绍一下具体怎么做的么
      

  3.   

    我认为delphi的ide同时也有一些简单的类似编译的功能,不断更具程序的更新归出类的结构,然后在你需要的时候将某个类的子方法或成员显示出来
    可是,这个功能可是vb和delphi曾经比拼过的功能,反正以我的水平恐怕是做不出来吧,最好是懂一点编译原理。
      

  4.   

    偶也知道和编译原理有关,
    关键是我的编译原理不是很好(简直就是很菜)可我还是想问在DELPHI里如何实现的
    谁能告诉我方法或者思路也成
      

  5.   

    别听编译原理胡说,那个不是你的要求~!如果说编译原理有关的话,我说跟汇编有关呢~!并不是这样的原理,这个原理应该跟showhint的原理类似
      

  6.   

    什么??showhint??你是指鼠标移动到某个控件上时显示的tooltip吗??
    你才不要瞎说呢这种功能根本不成问题,关键的是显示的内容。
      

  7.   

    Code insight? 相当于做一个语法分析器吧,这可不是一个贴子能找到解答的问题。pazze说得不错,看看编译原理吧。
      

  8.   

    先谢谢几位的帮忙,
    我现在正在跟一个人做一个解释器(呵呵,他是高手,偶只是跟着学得)
    他以前已经完成了很多,语法分析及词法分析的功能,
    但是现在想添加Code Insight功能我想问像 westfly(西翔)  所说的"在然后在光标处创建一个列表选择框"应该怎么做,
    我听说好像有个API函数能让窗口显示在最上层,但偶实在是不知道是那个
    查了一下手头的资料也没找到,希望各位能指点一二
    麻烦各位了
      

  9.   

    给个例子给你,当然,你的实现应该不会这么简单的,仅供参考:=============================================================unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Printers, StdCtrls, ComCtrls, Clipbrd;type
      TSymbolInsightListBox = class(TCustomListBox)
      private
        fEditor: TMemo;
        procedure WMCancelMode(var Message: TMessage); message WM_CancelMode;
        procedure SetEditor(const Value: TMemo);
     protected
        procedure CreateParams(var Params: TCreateParams); override;    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
            override;
        procedure Notification(aComponent: TComponent; aOperation: TOperation);
            override;
      public
        constructor Create(aOwner: TComponent); override;
        procedure Show(aCaretPos: TPoint);
        procedure Hide;
        property Editor: TMemo read fEditor write SetEditor;
      end;  TForm1 = class(TForm)
        Memo1: TMemo;
        procedure Memo1KeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        fSymbolInsight: TSymbolInsightListBox;
      protected  public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TSymbolInsightListBox }constructor TSymbolInsightListBox.Create(aOwner: TComponent);
    begin
      inherited;
      Visible := False;
    end;procedure TSymbolInsightListBox.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;
    end;procedure TSymbolInsightListBox.Hide;
    begin
      Visible := False;
    end;procedure TSymbolInsightListBox.MouseUp(Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      I, vSelStart: Integer;
    begin
      inherited;  //下面是简单的插入代码
      I := ItemAtPos(Point(X, Y), True);
      if (I > -1) and (fEditor <> nil) then
      begin
        vSelStart := fEditor.SelStart;
        fEditor.SelText := Items[I];
        if fEditor.Visible then
          fEditor.SelStart := vSelStart + Length(Items[I]);
      end;  if fEditor <> nil then
        fEditor.SetFocus;  Hide;
    end;procedure TSymbolInsightListBox.Notification(aComponent: TComponent;
      aOperation: TOperation);
    begin
      inherited;
      if (aComponent = fEditor) and (aOperation = opRemove) then
        fEditor := nil; 
    end;procedure TSymbolInsightListBox.SetEditor(const Value: TMemo);
    begin
      if fEditor <> nil then fEditor.RemoveFreeNotification(Self);
      fEditor := Value;
      if fEditor <> nil then fEditor.FreeNotification(Self);
    end;procedure TSymbolInsightListBox.Show(aCaretPos: TPoint);
    begin
      Left := aCaretPos.X;
      Top := aCaretPos.Y;
      Visible := True;
    end;procedure TSymbolInsightListBox.WMCancelMode(var Message: TMessage);
    begin
      Visible := False;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      fSymbolInsight := TSymbolInsightListBox.Create(Self);
      fSymbolInsight.Parent := Self;
      fSymbolInsight.Editor := Memo1;
    end;procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      vCaretPos: TPoint;
      vSize: TSize;
      vDC: HDC;
    begin
      if (Key = VK_ESCAPE) and (Shift = []) then
        fSymbolInsight.Hide
      else if (fSymbolInsight.Visible and not (Key in [VK_UP, VK_DOWN, VK_LEFT_RIGHT]))
      or ((Shift = [ssCtrl]) and (Key = VK_SPACE)) then
      begin
        //再这里分析上下文,决定listbox的内容
        fSymbolInsight.Clear;
        fSymbolInsight.Items.Add('procedure Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState)');    GetCaretPos(vCaretPos);
        vDC := GetDC(Memo1.Handle);
        try
          GetTextExtentPoint(vDC, 'H', 1, vSize);
        finally
          if (GetClassLong(Memo1.Handle, GCL_STYLE) or CS_OWNDC) = 0 then
            ReleaseDC(Memo1.Handle, vDC);
        end;
        vCaretPos.Y := vCaretPos.Y + vSize.cy + 1;
        vCaretPos := Memo1.ClientToParent(vCaretPos);
        fSymbolInsight.Show(vCaretPos);
      end;
      //else 设置ListBox的ItemIndex等等动作
    end;
    end.
      

  10.   

    把上面的改进一下,应该会更好:procedure TSymbolInsightListBox.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.WndParent=0;
      Params.ExStyle=Params.ExStyle or WS_EX_PALETTEWINDOW;
      //Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;
    end;
      

  11.   

    我倒,又忘了改“=”!把上面的改进一下,应该会更好:procedure TSymbolInsightListBox.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.WndParent:=0;
      Params.ExStyle:=Params.ExStyle or WS_EX_PALETTEWINDOW;
      //Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;
    end;
      

  12.   

    谢谢各位,问题才解决,所以结贴也就晚了点偶现在实现的功能很简单,只是查找预先定义好的函数,不过以后会慢慢改进的
    偶先查找光标所在的位置,在该位置处创建了一个listbox,将以前已经定义好的函数写入,同时赋相应的事件(如回车,上下键,Esc键,以及文本输入区change事件等)
    当选定相应的函数之后,取出函数名,然后向左查找一直找到行的起始位置或者遇到截至符停止,再向右查找也是找到头或截至符为止(截止符由自己定义,如空格,分号等),然后选中这一区域,用选择的函数替换区域里的字体。
    以后还会添加功能:如分析前一个变量是那一种类型的变量,然后在函数列表或变量列表里筛选后再显示;输入一个过程后,过程变量类型需要的showhint提示等,暂时就想到这些,估计又够偶忙一阵了。谢谢各位的帮忙!!!!
      

  13.   

    在上面帮忙的各位大侠
    别忘了到http://expert.csdn.net/Expert/topic/1238/1238492.xml?temp=.5250666
    上‘登陆’一下,偶把分散了好结贴,呵呵这样结贴率就可以100%了
    祝各位圣诞快乐!!