输入助手单词列表类定义单元在处理LoadFromSysPath时会漏掉单元的简单处理办法
在Uses节输入引用单元的时候,输入助手可以自动提示系统中的所有可引用单元文件列表,但是最近的版本似乎只能识别系统内置的单元,而对用户自己安装的组件不起作用。
单元的列表来自CnInputSymbolList的TUnitNameList类,类的LoadFromSysPath用于获取系统中搜索路径和Lib路径中的pas和dcu文件列表,其中GetLibraryPath用于获取库路径,原始代码如下:
procedure TUnitNameList.LoadFromSysPath;
var
I: Integer;
Paths: TStringList;
begin
Paths := TStringList.Create;
try
Paths.Sorted := True;
GetLibraryPath(Paths, False);
if not SameText(Paths.Text, FSysPath) then
begin
FSysUnits.Clear;
FCurrList := FSysUnits;
for I := 0 to Paths.Count - 1 do
begin
FindFile(Paths[I], '*.pas', DoFindFile, nil, False, False);
FindFile(Paths[I], '*.dcu', DoFindFile, nil, False, False);
end;
FindFile(MakePath(GetInstallDir) + 'Lib\', '*.dcu', DoFindFile, nil,
False, False);
UpdateCaseFromModules(FSysUnits);
FSysPath := Paths.Text;
end;
finally
Paths.Free;
end;
for I := 0 to FSysUnits.Count - 1 do
AddUnit(FSysUnits[I]);
end;
// 取环境设置中的 LibraryPath 内容
procedure GetLibraryPath(Paths: TStrings; IncludeProjectPath: Boolean);
var
Svcs: IOTAServices;
Options: IOTAEnvironmentOptions;
Text: string;
List: TStrings;
procedure AddList(AList: TStrings);
var
S: string;
i: Integer;
begin
for i := 0 to List.Count - 1 do
begin
S := Trim(MakePath(List));
if (S <> '') and (Paths.IndexOf(S) < 0) then
Paths.Add(S);
end;
end;
begin
Svcs := BorlandIDEServices as IOTAServices;
if not Assigned(Svcs) then Exit;
Options := Svcs.GetEnvironmentOptions;
if not Assigned(Options) then Exit;
List := TStringList.Create;
try
Text := ReplaceToActualPath(Options.GetOptionValue('LibraryPath'));
List.Text := StringReplace(Text, ';', #13#10, [rfReplaceAll]);
AddList(List);
Text := ReplaceToActualPath(Options.GetOptionValue('BrowsingPath'));
List.Text := StringReplace(Text, ';', #13#10, [rfReplaceAll]);
AddList(List);
if IncludeProjectPath then
begin
GetProjectLibPath(List);
AddList(List);
end;
finally
List.Free;
end;
end;
问题出在Options.GetOptionValue('LibraryPath')和Options.GetOptionValue('BrowsingPath'),它们获取的信息不全,直接读取注册表相关键值后能够把所有的单元加载进单元列表,把代码改动如下,但是这个改动只适合特定的平台和Delphi版本,依然有缺陷,不过暂时够我用了,希望开发者看看这个问题,找个完善的解决方案。
// Text := ReplaceToActualPath(Options.GetOptionValue('LibraryPath'));
Text := ReplaceToActualPath(RegReadStringDef(HKEY_CURRENT_USER,
'Software\Embarcadero\BDS\17.0\Library\Win32','Search Path',''));
// Text := ReplaceToActualPath(Options.GetOptionValue('BrowsingPath'));
Text := ReplaceToActualPath(RegReadStringDef(HKEY_CURRENT_USER,
'Software\Embarcadero\BDS\17.0\Library\Win32','Browsing Path',''));
[ 本帖最后由 xychen 于 2015-12-9 12:15 编辑 ]
|