在程式中匯入了一個OCX控制元件,其中使用的引數為如下兩個:
function receiveMessage(var NetID: Smallint; var NodeID: Smallint; var UnitID: Smallint;
MessageType: OleVariant): OleVariant;
function sendFinsCommand(NetID: Smallint; NodeID: Smallint; UnitID: Smallint;
Message: OleVariant): Integer; overload;
撰寫程式為:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, DBOleCtl, FINSMSGCTLLib_TLB;
type
TForm1 = class(TForm)
fnsmsg1: TFinsMsg;
btn1: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
procedure fnsmsg1Receive(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
fnsmsg1.sendFinsCommand(0,2,0,'0701');
end;
procedure TForm1.fnsmsg1Receive(Sender: TObject);
var
a,b,c:SmallInt;
messagefins:OleVariant;
s:string;
begin
a:=0;
b:=2;
c:=0;
s := fnsmsg1.receiveMessage(a,b,c,messagefins);
end;
end.
單擊“btn1",程式執行,發送指令:fnsmsg1.sendFinsCommand(0,2,0,'0701');順序執行。控制元件接收到指令后,開始自動運行fnsmsg1Receive函式,到 s := fnsmsg1.receiveMessage(a,b,c,messagefins);行,系統拋出如下錯誤:
Project Project1.exe raised exception class EOleException with message "Unsupported Variant Type on the Method argument".Process stopped.
我把messagefins變為String型別也是一樣的。
請大神給出較為詳細的分析,最好能給出點嗎,謝謝!
uj5u.com熱心網友回復:
messagefins的值是多少,從代碼上看,a,b,c都有賦值,messagefins沒有賦值?uj5u.com熱心網友回復:
試試 s := fnsmsg1.receiveMessage(0,2,0,'0701'); 可有錯誤!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/88796.html
標籤:VCL組件開發及應用
