如何实现VB/Delphi式提示!?(200分)

  • 主题发起人 主题发起人 myhxg
  • 开始时间 开始时间
M

myhxg

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样才能实现如VB/DELPHi那样的点提示,就是输入对象名加点时出现的那个属性提示!?谁会吗!?
 
你要做编辑器吗?
 
像那种基于编译器的提示看来不容易<br><br>但象vb那种基于库的提示还是可能的,就是判断.前的词汇<br>再从数据库中找出相关项<br>用个列表来显示<br>实际上可能也没那么简单,只是我想得简单了点
 
这个算法蛮复杂的,VC的提示相对于Delphi就慢很多
 
VB的很简单,建立一个库.把所有的的都列出来<br><br>而Delphi会自动匹配类型,不匹配的会自动去掉.
 
这个问题建立在对 dcu 文件的分析上面,这是不会轻易提供的,如果你希望建立一个针对<br>Code Insight 技术的 Experts ,可以通过实现 IOTACodeInsightManager 接口来实现一些<br>设置或者增强,<br><br><br>如果你希望建立自己的Code Insight,可以使用 SynEdit 控件包,它已经将这个功能封装<br>好了控件,<br><br>http://synedit.sourceforge.net<br><br>...............................<br>interface<br><br>&nbsp; var MyCodeInsightManagerIndex: Integer; // Don't like global<br>variables<br>&nbsp; // but here it's necessary<br><br>implementation<br>...............................<br>type<br>&nbsp; MyCodeInsightManager = class(TNotifierObject, IOTACodeInsightManager)<br>&nbsp; public<br>&nbsp; &nbsp; procedure AllowCodeInsight(var Allow: Boolean; const Key: Char);<br>&nbsp; &nbsp; procedure Done(Accepted: Boolean; out DisplayParams: Boolean);<br>&nbsp; &nbsp; function EditorTokenValidChars(PreValidating: Boolean):<br>TSysCharSet;<br>&nbsp; &nbsp; procedure GetCodeInsightType(AChar: Char; AElement: Integer;<br>&nbsp; &nbsp; &nbsp; out CodeInsightType: TOTACodeInsightType; out InvokeType:<br>TOTAInvokeType);<br>&nbsp; &nbsp; function GetEnabled: Boolean;<br>&nbsp; &nbsp; function GetHintText(HintLine, HintCol: Integer): string;<br>&nbsp; &nbsp; function GetIDStrings: string;<br>&nbsp; &nbsp; function GetLongestItem: string;<br>&nbsp; &nbsp; function GetMultiSelect: Boolean;<br>&nbsp; &nbsp; function GetName: string;<br>&nbsp; &nbsp; procedure GetParameterList(out ParameterList:IOTACodeInsightParameterList);<br>&nbsp; &nbsp; procedure GetSymbolList(out SymbolList:IOTACodeInsightSymbolList);<br>&nbsp; &nbsp; function GotoDefinition(out AFileName: string; out ALineNum:Integer;<br>&nbsp; &nbsp; &nbsp; Index: Integer = -1): Boolean;<br>&nbsp; &nbsp; function HandlesFile(const AFileName: string): Boolean;<br>&nbsp; &nbsp; function InvokeCodeCompletion(HowInvoked: TOTAInvokeType; var Str:string):<br>&nbsp; &nbsp; &nbsp; Boolean;<br>&nbsp; &nbsp; function InvokeParameterCodeInsight(HowInvoked: TOTAInvokeType; <br>&nbsp; &nbsp; &nbsp; var SelectedIndex: Integer): Boolean;<br>&nbsp; &nbsp; function IsViewerBrowsable(Index: Integer): Boolean;<br>&nbsp; &nbsp; procedure OnEditorKey(Key: Char; var CloseViewer: Boolean; var Accept:Boolean);<br>&nbsp; &nbsp; procedure ParameterCodeInsightAnchorPos(var EdPos: TOTAEditPos);<br>&nbsp; &nbsp; function ParameterCodeInsightParamIndex(EdPos: TOTAEditPos):<br>Integer;<br>&nbsp; &nbsp; function PreValidateCodeInsight(const Str: string): Boolean;<br>&nbsp; &nbsp; procedure SetEnabled(Value: Boolean);<br><br>&nbsp; end;<br><br><br>{ MyCodeInsightManager }<br><br>procedure MyCodeInsightManager.AllowCodeInsight(var Allow: Boolean;<br>&nbsp; const Key: Char);<br>begin<br>// I would like to activate my code completion manager when the user<br>// presses the ' button<br>&nbsp; if Key = #39 then // It's the quote symbol<br>&nbsp; &nbsp; Allow := True<br>&nbsp; else<br>&nbsp; &nbsp; Allow := False;<br>end;<br><br>procedure MyCodeInsightManager.Done(Accepted: Boolean;<br>&nbsp; out DisplayParams: Boolean);<br>begin<br>&nbsp; if Accepted then<br>&nbsp; begin<br>&nbsp; &nbsp; // Here I should insert the text in the Editor<br>&nbsp; end;<br>end;<br><br>function MyCodeInsightManager.EditorTokenValidChars(<br>&nbsp; PreValidating: Boolean): TSysCharSet;<br>begin<br>// I don't really understand what this function must return.<br>// I return the quote symbol here because I would like to activate<br>// my manager when the user presses the ' button, but I am not sure<br>// whether this is correct<br>&nbsp; Result := [''''];<br>end;<br><br>procedure MyCodeInsightManager.GetCodeInsightType(AChar: Char;<br>&nbsp; AElement: Integer; out CodeInsightType: TOTACodeInsightType;<br>&nbsp; out InvokeType: TOTAInvokeType);<br>begin<br>&nbsp; CodeInsightType := citCodeInsight; // I want to perform code<br>completion<br>&nbsp; InvokeType := itAuto; //????????????????????????????????????<br>end;<br><br>function MyCodeInsightManager.GetEnabled: Boolean;<br>begin<br>&nbsp; Result := True;<br>end;<br><br>function MyCodeInsightManager.GetHintText(HintLine,<br>&nbsp; HintCol: Integer): string;<br>begin<br>&nbsp; Result := ''; // I return an empty string here because I don't want<br>&nbsp; // my manager to perform tooltip help<br>end;<br><br>function MyCodeInsightManager.GetIDString: string;<br>begin<br>&nbsp; Result := 'MyCompany.Code.Completion.Manager';<br>end;<br><br>function MyCodeInsightManager.GetLongestItem: string;<br>begin<br>&nbsp; Result := 'AAAAAAAAAAAAAAAAAAAAAAAAAA';<br>end;<br><br>function MyCodeInsightManager.GetMultiSelect: Boolean;<br>begin<br>&nbsp; Result := False; // I don't want to let the user select multiple<br>&nbsp; // items in the code completion viewer<br>end;<br><br>function MyCodeInsightManager.GetName: string;<br>begin<br>&nbsp; Result := 'Code Completion Manager';<br>end;<br><br>procedure MyCodeInsightManager.GetParameterList(<br>&nbsp; out ParameterList: IOTACodeInsightParameterList);<br>begin<br>&nbsp; ParameterList := nil; // I don't want my manager to perform function<br>&nbsp; //parameter insight, so I return nil here.<br>end;<br><br>procedure MyCodeInsightManager.GetSymbolList(<br>&nbsp; out SymbolList: IOTACodeInsightSymbolList);<br>begin<br>&nbsp; SymbolList := TMySymbolList.Create;<br>&nbsp; // Suppose here I should return an instance to a class that<br>&nbsp; // implements IOTACodeInsightSymbolList interface or maybe<br>&nbsp; // I am wrong?<br>end;<br><br>function MyCodeInsightManager.GotoDefinition(out AFileName: string;<br>&nbsp; out ALineNum: Integer; Index: Integer): Boolean;<br>begin<br>&nbsp; AFileName := '';<br>&nbsp; ALineNum := 0;<br>&nbsp; Result := True;<br>&nbsp; // I don't want to use symbol browsing in my manager<br>end;<br><br>function MyCodeInsightManager.HandlesFile(<br>&nbsp; const AFileName: string): Boolean;<br>begin<br>&nbsp; if ExtractFileExt(AFileName) = '.pas' then<br>&nbsp; &nbsp; Result := True<br>&nbsp; else<br>&nbsp; &nbsp; Result := False;<br>end;<br><br>function MyCodeInsightManager.InvokeCodeCompletion(<br>&nbsp; HowInvoked: TOTAInvokeType; var Str: string): Boolean;<br>begin<br>&nbsp; Result := True;<br>&nbsp; // What should I do with the HowInvoked and Str variables?<br>end;<br><br>function MyCodeInsightManager.InvokeParameterCodeInsight(<br>&nbsp; HowInvoked: TOTAInvokeType; var SelectedIndex: Integer): Boolean;<br>begin<br>&nbsp; Result := False; // No Parameter Insight in my manager<br>end;<br><br>function MyCodeInsightManager.IsViewerBrowsable(Index: Integer):<br>Boolean;<br>begin<br>&nbsp; Result := True; // I want all the symbols in the code completion<br>viewer<br>&nbsp; // to be browsable<br>end;<br><br>procedure MyCodeInsightManager.OnEditorKey(Key: Char; var CloseViewer,<br>&nbsp; Accept: Boolean);<br>begin<br>&nbsp; if Key = #13 then // Carriage return<br>&nbsp; begin<br>&nbsp; &nbsp; Accept := True; // Accept the symbol that is currently selected<br>&nbsp; &nbsp; CloseViewer := True;<br>&nbsp; end;<br>&nbsp; if Key = #27 then // ESC key<br>&nbsp; begin<br>&nbsp; &nbsp; Accept := False; // Do not accept the symbol<br>&nbsp; &nbsp; CloseViewer := True;<br>&nbsp; end;<br>end;<br><br>procedure MyCodeInsightManager.ParameterCodeInsightAnchorPos(<br>&nbsp; var EdPos: TOTAEditPos);<br>begin<br>// Don't want Parameter Insight Tooltip window in my manager<br>end;<br><br>function MyCodeInsightManager.ParameterCodeInsightParamIndex(<br>&nbsp; EdPos: TOTAEditPos): Integer;<br>begin<br>// I have no idea what to do with this function<br>end;<br><br>function MyCodeInsightManager.PreValidateCodeInsight(<br>&nbsp; const Str: string): Boolean;<br>begin<br>&nbsp; Result := True; // Not quite sure about this. Maybe I should<br>&nbsp; // make some filters using the Str variable before returning<br>end;<br><br>procedure MyCodeInsightManager.SetEnabled(Value: Boolean);<br>begin<br>&nbsp; // I don't have this property in my implementation<br>end;<br><br>...............................<br><br><br>initialization<br>&nbsp; MyCodeInsightManagerIndex := (BorlandIDEServices as <br>&nbsp; &nbsp; IOTACodeInsightServices).AddCodeInsightManager(MyCodeInsightManager.Create);<br><br>finalization<br>&nbsp; (BorlandIDEServices as <br>&nbsp; &nbsp; IOTACodeInsightServices).RemoveCodeInsightManager(<br>&nbsp; &nbsp; &nbsp; MyCodeInsightManagerIndex);<br><br>end.<br><br>------------------------------------------------------------------<br>
 
后退
顶部