这个问题建立在对 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> var MyCodeInsightManagerIndex: Integer; // Don't like global<br>variables<br> // but here it's necessary<br><br>implementation<br>...............................<br>type<br> MyCodeInsightManager = class(TNotifierObject, IOTACodeInsightManager)<br> public<br> procedure AllowCodeInsight(var Allow: Boolean; const Key: Char);<br> procedure Done(Accepted: Boolean; out DisplayParams: Boolean);<br> function EditorTokenValidChars(PreValidating: Boolean):<br>TSysCharSet;<br> procedure GetCodeInsightType(AChar: Char; AElement: Integer;<br> out CodeInsightType: TOTACodeInsightType; out InvokeType:<br>TOTAInvokeType);<br> function GetEnabled: Boolean;<br> function GetHintText(HintLine, HintCol: Integer): string;<br> function GetIDStrings: string;<br> function GetLongestItem: string;<br> function GetMultiSelect: Boolean;<br> function GetName: string;<br> procedure GetParameterList(out ParameterList:IOTACodeInsightParameterList);<br> procedure GetSymbolList(out SymbolList:IOTACodeInsightSymbolList);<br> function GotoDefinition(out AFileName: string; out ALineNum:Integer;<br> Index: Integer = -1): Boolean;<br> function HandlesFile(const AFileName: string): Boolean;<br> function InvokeCodeCompletion(HowInvoked: TOTAInvokeType; var Str:string):<br> Boolean;<br> function InvokeParameterCodeInsight(HowInvoked: TOTAInvokeType; <br> var SelectedIndex: Integer): Boolean;<br> function IsViewerBrowsable(Index: Integer): Boolean;<br> procedure OnEditorKey(Key: Char; var CloseViewer: Boolean; var Accept:Boolean);<br> procedure ParameterCodeInsightAnchorPos(var EdPos: TOTAEditPos);<br> function ParameterCodeInsightParamIndex(EdPos: TOTAEditPos):<br>Integer;<br> function PreValidateCodeInsight(const Str: string): Boolean;<br> procedure SetEnabled(Value: Boolean);<br><br> end;<br><br><br>{ MyCodeInsightManager }<br><br>procedure MyCodeInsightManager.AllowCodeInsight(var Allow: Boolean;<br> const Key: Char);<br>begin<br>// I would like to activate my code completion manager when the user<br>// presses the ' button<br> if Key = #39 then // It's the quote symbol<br> Allow := True<br> else<br> Allow := False;<br>end;<br><br>procedure MyCodeInsightManager.Done(Accepted: Boolean;<br> out DisplayParams: Boolean);<br>begin<br> if Accepted then<br> begin<br> // Here I should insert the text in the Editor<br> end;<br>end;<br><br>function MyCodeInsightManager.EditorTokenValidChars(<br> 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> Result := [''''];<br>end;<br><br>procedure MyCodeInsightManager.GetCodeInsightType(AChar: Char;<br> AElement: Integer; out CodeInsightType: TOTACodeInsightType;<br> out InvokeType: TOTAInvokeType);<br>begin<br> CodeInsightType := citCodeInsight; // I want to perform code<br>completion<br> InvokeType := itAuto; //????????????????????????????????????<br>end;<br><br>function MyCodeInsightManager.GetEnabled: Boolean;<br>begin<br> Result := True;<br>end;<br><br>function MyCodeInsightManager.GetHintText(HintLine,<br> HintCol: Integer): string;<br>begin<br> Result := ''; // I return an empty string here because I don't want<br> // my manager to perform tooltip help<br>end;<br><br>function MyCodeInsightManager.GetIDString: string;<br>begin<br> Result := 'MyCompany.Code.Completion.Manager';<br>end;<br><br>function MyCodeInsightManager.GetLongestItem: string;<br>begin<br> Result := 'AAAAAAAAAAAAAAAAAAAAAAAAAA';<br>end;<br><br>function MyCodeInsightManager.GetMultiSelect: Boolean;<br>begin<br> Result := False; // I don't want to let the user select multiple<br> // items in the code completion viewer<br>end;<br><br>function MyCodeInsightManager.GetName: string;<br>begin<br> Result := 'Code Completion Manager';<br>end;<br><br>procedure MyCodeInsightManager.GetParameterList(<br> out ParameterList: IOTACodeInsightParameterList);<br>begin<br> ParameterList := nil; // I don't want my manager to perform function<br> //parameter insight, so I return nil here.<br>end;<br><br>procedure MyCodeInsightManager.GetSymbolList(<br> out SymbolList: IOTACodeInsightSymbolList);<br>begin<br> SymbolList := TMySymbolList.Create;<br> // Suppose here I should return an instance to a class that<br> // implements IOTACodeInsightSymbolList interface or maybe<br> // I am wrong?<br>end;<br><br>function MyCodeInsightManager.GotoDefinition(out AFileName: string;<br> out ALineNum: Integer; Index: Integer): Boolean;<br>begin<br> AFileName := '';<br> ALineNum := 0;<br> Result := True;<br> // I don't want to use symbol browsing in my manager<br>end;<br><br>function MyCodeInsightManager.HandlesFile(<br> const AFileName: string): Boolean;<br>begin<br> if ExtractFileExt(AFileName) = '.pas' then<br> Result := True<br> else<br> Result := False;<br>end;<br><br>function MyCodeInsightManager.InvokeCodeCompletion(<br> HowInvoked: TOTAInvokeType; var Str: string): Boolean;<br>begin<br> Result := True;<br> // What should I do with the HowInvoked and Str variables?<br>end;<br><br>function MyCodeInsightManager.InvokeParameterCodeInsight(<br> HowInvoked: TOTAInvokeType; var SelectedIndex: Integer): Boolean;<br>begin<br> Result := False; // No Parameter Insight in my manager<br>end;<br><br>function MyCodeInsightManager.IsViewerBrowsable(Index: Integer):<br>Boolean;<br>begin<br> Result := True; // I want all the symbols in the code completion<br>viewer<br> // to be browsable<br>end;<br><br>procedure MyCodeInsightManager.OnEditorKey(Key: Char; var CloseViewer,<br> Accept: Boolean);<br>begin<br> if Key = #13 then // Carriage return<br> begin<br> Accept := True; // Accept the symbol that is currently selected<br> CloseViewer := True;<br> end;<br> if Key = #27 then // ESC key<br> begin<br> Accept := False; // Do not accept the symbol<br> CloseViewer := True;<br> end;<br>end;<br><br>procedure MyCodeInsightManager.ParameterCodeInsightAnchorPos(<br> var EdPos: TOTAEditPos);<br>begin<br>// Don't want Parameter Insight Tooltip window in my manager<br>end;<br><br>function MyCodeInsightManager.ParameterCodeInsightParamIndex(<br> EdPos: TOTAEditPos): Integer;<br>begin<br>// I have no idea what to do with this function<br>end;<br><br>function MyCodeInsightManager.PreValidateCodeInsight(<br> const Str: string): Boolean;<br>begin<br> Result := True; // Not quite sure about this. Maybe I should<br> // make some filters using the Str variable before returning<br>end;<br><br>procedure MyCodeInsightManager.SetEnabled(Value: Boolean);<br>begin<br> // I don't have this property in my implementation<br>end;<br><br>...............................<br><br><br>initialization<br> MyCodeInsightManagerIndex := (BorlandIDEServices as <br> IOTACodeInsightServices).AddCodeInsightManager(MyCodeInsightManager.Create);<br><br>finalization<br> (BorlandIDEServices as <br> IOTACodeInsightServices).RemoveCodeInsightManager(<br> MyCodeInsightManagerIndex);<br><br>end.<br><br>------------------------------------------------------------------<br>