【发布时间】:2015-11-26 22:52:35
【问题描述】:
我不断收到此错误“无效的浮点运算”。
我在 Delphi 7 上。
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
TlHelp32, Dialogs, StdCtrls, ExtCtrls, Buttons, ComCtrls;
var //global
PHandle, cancel, bytes, scantype: integer;
...
procedure Tmain.scanbtnClick(Sender: TObject);
var max, address: Integer;
floatinput, floatinput1, floatinput2, datafloat: Real;
x: cardinal;
itm: TListItem;
begin
floatinput := StrToFloat(Trim(valueinput.Text));
floatinput1 := StrToFloat(Trim(valueinput1.Text));
floatinput2 := StrToFloat(Trim(valueinput2.Text));
if floatinput2 < floatinput1 then
begin
floatinput1 := floatinput1 + floatinput2;
floatinput2 := floatinput1 - floatinput2;
floatinput1 := floatinput1 - floatinput2;
end;
result.Show;
x := 0;
address := 0;
result.resultlist.Clear;
repeat
Application.ProcessMessages;
statusbar1.Panels.Items[1].Text := 'Searching... ' + IntToStr(address * 100 div max) + '% (' + IntToStr(address div bytes) + ' out of ' + IntToStr(max div bytes) + ').';
if ReadprocessMemory(PHandle, Ptr(address), @datafloat, bytes, x) then
begin
if (x > 0) then
begin
if scantype = 0 then
begin
if datafloat = floatinput then //error here
begin
itm := result.resultlist.Items.Add;
itm.Caption := '0x' + IntToHex(address,8);
itm.SubItems.Add(FormatFloat('0.0#########', datafloat));
end;
end;
if scantype = 1 then
begin
if datafloat > floatinput //also here
then begin
itm := result.resultlist.Items.Add;
itm.Caption := '0x' + IntToHex(address,8);
itm.SubItems.Add(FormatFloat('0.0#########', datafloat));
end;
end;
if scantype = 2 then
begin
if datafloat < floatinput //here too
then begin
itm := result.resultlist.Items.Add;
itm.Caption := '0x' + IntToHex(address,8);
itm.SubItems.Add(FormatFloat('0.0#########', datafloat));
end;
end;
if scantype = 2 then
begin
if (dataint <= intinput2) and (dataint >= intinput1) //even here
then begin
itm := result.resultlist.Items.Add;
itm.Caption := '0x' + IntToHex(address,8);
itm.SubItems.Add(FormatFloat('0.0#########', datafloat));
end;
end;
end;
end;
if x <> 0
then address := address + x
else address := address + bytes;
until (address >= Max) or (cancel = 1);
end;
我什至检查了 cpu 窗口,这是因为它试图从指向空值的指针加载浮点值。
这不是 ReadMemory,因为这小段代码在 while 循环中,它在遇到此错误之前返回几个有效值。
我该怎么办?
提前致谢。
【问题讨论】:
-
datafloat 是什么数据类型?您将其与变体(Null)进行比较,但变体不是与 ReadProcessMemory 兼容的类型。您的意思是使用 Double 吗?
-
您发布的代码将无法编译,因为在 Delphi 中,
NULL的唯一有效用途是在使用变体时。请发布您正在使用的完整的实际代码。要求我们调试实际上不是您的代码的代码既浪费您的时间,也浪费我们的时间。如果您需要帮助,请在此处发布可演示问题的可编译 MCVE。 -
@GerryColl datafloat 是真实的。你能解释一下当我尝试将一个值与 null 进行比较时到底发生了什么吗?
-
@KenWhite 完整的代码实际上有点大,没有必要用可能与问题无关的东西来填充主题。我可以提供哪些信息来帮助您看得更清楚?
-
然后将其缩减为首先演示问题所需的最少代码。我们无法调试我们看不到的代码,或者无法编译的代码。正如我之前问过的,请发布一个我们可以使用的 MCVE。
标签: delphi point floating operation