gpt4 book ai didi

delphi - Delphi 7 中 For..in 循环的替代方案?

转载 作者:行者123 更新时间:2023-12-03 15:16:46 31 4
gpt4 key购买 nike

编译此代码时,我在 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;

错误消息:

[Error] Project1.dpr(52): Operator not applicable to this operand type

有什么替代方法吗?或者我该如何解决它?

最佳答案

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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com