编译此代码时,我在使用 Delphi 7 for in 循环时遇到错误 Link

procedure GetProcessorInfo;
Var
  SMBios             : TSMBios;
  LProcessorInfo     : TProcessorInformation;
  LSRAMTypes         : TCacheSRAMTypes;
begin
  SMBios:=TSMBios.Create;
  try
      WriteLn('Processor Information');
      if SMBios.HasProcessorInfo then
      for LProcessorInfo in SMBios.ProcessorInfo do // <-- Error here
      begin
        ...
      end;
  ...
end;

错误信息:



任何替代方式?或者我该如何解决?

最佳答案

Delphi 7 不支持 for .. in ,所以你必须自己迭代 TSMBios.ProcessorInfo 数组

procedure GetProcessorInfo;
Var
  SMBios             : TSMBios;
  LProcessorInfo     : TProcessorInformation;
  LSRAMTypes         : TCacheSRAMTypes;
  LIdx : Integer; // add this
begin
  SMBios:=TSMBios.Create;
  try
    WriteLn('Processor Information');
    if SMBios.HasProcessorInfo then
      // for LProcessorInfo in SMBios.ProcessorInfo do
      for LIdx := Low( SMBios.ProcessorInfo ) to High( SMBios.ProcessorInfo ) do
      begin
        LProcessorInfo := SMBios.ProcessorInfo[LIdx];
        ...
      end;
  ...
end;

关于delphi - Delphi 7 中 For..in 循环的替代方案?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23730191/

10-10 16:59