CnPack Forum


 
Subject: Version: 1.0.9.798 有个地方有问题
hq200306
灌水科科长
Rank: 3Rank: 3



UID 67758
Digest Posts 0
Credits 102
Posts 35
点点分 102
Reading Access 10
Registered 2012-12-1
Status Offline
Post at 2015-11-24 13:36  Profile | Blog | P.M. 
Version: 1.0.9.798 有个地方有问题

procedure TCnWizardMgr.CheckKeyMappingEnhModulesSequence;
const
  PRIORITY_KEY = 'Priority';
  CASTALIA_KEYNAME = 'Castalia';
  CNPACK_KEYNAME = 'CnPack';
var
  List: TStringList;
  Reg: TRegistry;
  I, {MinIdx,} MaxIdx, CnPackIdx, MinValue, MaxValue: Integer;
  Contain: Boolean;
begin
  // XE8/10 Seattle 下 IDE 集成的 Castalia 的快捷键和 CnPack 有冲突,
  // 规则:有 Castalia 名字存在,且 CnPack 的 Priority 不是最大,则提示。
  List := TStringList.Create;
  try
    if GetKeysInRegistryKey(WizOptions.CompilerRegPath + KEY_MAPPING_REG, List) then
    begin
      if List.Count <= 1 then
        Exit;

      // List 中存了每个 Key 的名字,Objects 里头存其 Priority 值
      for I := 0 to List.Count - 1 do
      begin
        List.Objects[I] := Pointer(-1);
        Reg := TRegistry.Create(KEY_READ);
        try
          if Reg.OpenKey(WizOptions.CompilerRegPath + KEY_MAPPING_REG + '\' + List[I], False) then
          begin
            List.Objects[I] := Pointer(Reg.ReadInteger(PRIORITY_KEY));
          end;
        finally
          Reg.Free;
        end;
{$IFDEF DEBUG}
        CnDebugger.LogFmt('Key Mapping: %s: Priority %d.', [List[I], Integer(List.Objects[I])]);
{$ENDIF}
      end;

      Contain := False;
      for I := 0 to List.Count - 1 do
      begin
        if Pos(CASTALIA_KEYNAME, List[I]) > 0 then
        begin
          Contain := True;
          Break;
        end;
      end;

      if not Contain then // 如果没 Castalia,大概就没冲突,不处理
        Exit;

      Contain := False;
      CnPackIdx := -1;
      for I := 0 to List.Count - 1 do
      begin
        if Pos(CNPACK_KEYNAME, List[I]) > 0 then
        begin
          Contain := True;
          CnPackIdx := I;
          Break;
        end;
      end;

      if not Contain then // 没 CnPack 的值,可能是第一次运行,只能提示
      begin
        InfoDlg(Format(SCnKeyMappingConflictsHint, [WizOptions.CompilerRegPath + KEY_MAPPING_REG]));
        Exit;
      end;

      // Both exist, check the priority of CnPack
      // MinIdx := 0;
      MaxIdx := 0;
      MinValue := Integer(List.Objects[0]);
      MaxValue := Integer(List.Objects[0]);
      for I := 0 to List.Count - 1 do
      begin
        if Integer(List.Objects[I]) < MinValue then
        begin
          //MinIdx := I;
          MinValue := Integer(List.Objects);
        end;

        if Integer(List.Objects[I]) > MaxValue then
        begin
          MaxIdx := I;
          MaxValue := Integer(List.Objects);
        end;
      end;

      if MaxIdx = CnPackIdx then // CnPack 键盘映射顺序已在最下面。
        Exit;

      InfoDlg(IntToStr(MaxIdx) + ':' + IntToStr(CnPackIdx) + ':' + Format(SCnKeyMappingConflictsHint, [WizOptions.CompilerRegPath + KEY_MAPPING_REG]));

    end;
  finally
    List.Free;
  end;
end;

{$ENDIF}
Top
hq200306
灌水科科长
Rank: 3Rank: 3



UID 67758
Digest Posts 0
Credits 102
Posts 35
点点分 102
Reading Access 10
Registered 2012-12-1
Status Offline
Post at 2015-11-24 13:37  Profile | Blog | P.M. 
具体是这里

for I := 0 to List.Count - 1 do
      begin
        if Integer(List.Objects[I]) < MinValue then
        begin
          //MinIdx := I;
          MinValue := Integer(List.Objects);
        end;

        if Integer(List.Objects[I]) > MaxValue then
        begin
          MaxIdx := I;
          MaxValue := Integer(List.Objects);
        end;
      end;
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6758
Posts 3555
点点分 6758
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2015-11-24 13:45  Profile | Blog | P.M. 
具体问题是什么,可否详细说一下?
Top
hq200306
灌水科科长
Rank: 3Rank: 3



UID 67758
Digest Posts 0
Credits 102
Posts 35
点点分 102
Reading Access 10
Registered 2012-12-1
Status Offline
Post at 2015-11-24 20:21  Profile | Blog | P.M. 
Version: 1.0.9.798 有个地方错了

MaxValue := Integer(List.Objects[0]);
      for I := 0 to List.Count - 1 do
      begin
        if Integer(List.Objects[I]) < MinValue then
        begin
          //MinIdx := I;
          MinValue := Integer(List.Objects[0]);//这里错了
        end;

        if Integer(List.Objects[I]) > MaxValue then
        begin
          MaxIdx := I;
          MaxValue := Integer(List.Objects[0]);//这里错了
        end;
      end;
Top
hq200306
灌水科科长
Rank: 3Rank: 3



UID 67758
Digest Posts 0
Credits 102
Posts 35
点点分 102
Reading Access 10
Registered 2012-12-1
Status Offline
Post at 2015-11-24 20:22  Profile | Blog | P.M. 
更正的代码

MaxValue := Integer(List.Objects[0]);
      for I := 0 to List.Count - 1 do
      begin
        if Integer(List.Objects[I]) < MinValue then
        begin
          //MinIdx := I;
          MinValue := Integer(List.Objects[ i]);
        end;

        if Integer(List.Objects[I]) > MaxValue then
        begin
          MaxIdx := I;
          MaxValue := Integer(List.Objects[ i]);
        end;
      end;


[ 本帖最后由 hq200306 于 2015-11-24 20:25 编辑 ]
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6758
Posts 3555
点点分 6758
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2015-11-25 10:19  Profile | Blog | P.M. 
说得太对了!我马上改正。疏忽疏忽。
Top
 




All times are GMT++8, the time now is 2024-4-26 06:58

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008278 second(s), 8 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP