程序报错: project project1.exe raised exception class EVariantInvalidArgError with message 'Invalid Argument' process stopped use stop or run to continue. procedure TForm1.send1;
var
SendCmd:OleVariant;
i:integer;
Value:oleVariant;
Rev: Array of Byte;
aa: Array [0..9] of Byte;
i_Count:integer;
Str: String;
GeList: Array[0..11] of Byte;
BChar: Array[0..1] of Char;begin
 try
Rev := nil;  // 初始化
Sendcmd:=VarArrayCreate([1,4],VarByte);
Value:=VarArrayCreate([1,7],VarByte);
Sendcmd[1]:=$31;
Sendcmd[2]:=$13;
Sendcmd[3]:=$01;
Sendcmd[4]:=$45;
MSComm1.Output:=Sendcmd;
Sleep(500);
    i_Count := msComm1.InBufferCount;
    Value := msComm1.Input;
    Rev := Value;   //光标运行到这里出错
    Str := '';
    for i := 0 to i_Count - 1 do
    begin
      aa[i] := Rev[i];
      BChar[0] := Chr(aa[i]);
      Str := Str + StrPas(BChar);
       Current1_1:=strtoint(str); //计算
   
    end;
     except      end;
end;

解决方案 »

  1.   

     Rev := Value;   //光标运行到这里出错
      

  2.   

    先问个问题,你得Rev 好像没有分配控件
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    SendCmd:OleVariant;
    Value:oleVariant;
    Rev: Array of Byte;
    A1,A2 : Pointer;
    begin
    Sendcmd:=VarArrayCreate([1,4],VarByte);
    Value:=VarArrayCreate([1,7],VarByte);
    Sendcmd[1]:=$31;
    Sendcmd[2]:=$13;
    Sendcmd[3]:=$01;
    Sendcmd[4]:=$45;SetLength(Rev,4);A1 :=  rev;
    A2 := VarArrayLock(sendCmd); Move(pAnsiChar(A2)^,PAnsiChar(A1)^,4);
     VarArrayUnlock(sendCmd);end;只是舉個例子,應該看得明白吧。沒有分醳內存,然後不要直接賦值。MOVE過去。
      

  4.   

    而且 Rev := Value这种赋值方式也是有问题的
      

  5.   

    程序报错: project project1.exe raised exception class EVariantInvalidArgError with message 'Invalid Argument' process stopped use stop or run to continue.