使用Delphi 2005,我創建了一個測試應用程序(使用TForm)來測試SOAP API。不幸的是,這個API已經聲明瞭一些由Delphi保留的枚舉(應用程序,系統和終端)。我重命名了SOAP文件(_Application,_Terminal和_System)中的枚舉,並能夠編寫OnBeforeExecute和OnAfterExecute方法,以在提交之前和之後用原始名稱替換這些重命名的枚舉。DELPHI:在TComponent中聲明HTTPRIO.OnBeforeExecute
我現在想納入我的較大項目這一點,並想捕獲所有的代碼在一個類文件(無格式)這個SOAP API。隨着我的測試程序,我添加了一個THTTPRIO對象的形式(從工具箱中),並可以很容易地設置在Object Inspector中OnBeforeExecute和OnAfterExecute方法。現在使用這個類(一個TComponent),我不能像使用表單那樣使用Tool Palette添加THTTPRIO對象。我試圖通過代碼創建THTTPRIO對象,但遇到一些錯誤。
我得到的錯誤E2009 incompatible types: 'Parameter lists differ'
上FEPS_HTTPRIO.OnAfterExecute := HTTPRIOAfterExecute;
(見下面的代碼)
爲什麼我得到的錯誤在這一點,但不是FEPS_HTTPRIO.OnBeforeExecute := HTTPRIOBeforeExecute;
,我怎麼能實現我的類中這兩種方法?
這是我如何通過代碼創建的THTTPRIO:
unit c_MoSh;
interface
uses classes, forms, Windows, SysUtils, c_MoShAPI, InvokeRegistry, controls;
Type
TMoSh = class(TComponent)
private
...
procedure HTTPRIOBeforeExecute(const MethodName: string;
var SOAPRequest: WideString);
procedure HTTPRIOAfterExecute(const MethodName: string;
var SOAPResponse: TStream);
...
constructor TMoSh.Create();
begin
FEPS_HTTPRIO := THTTPRIO.Create(self);
FEPS_HTTPRIO.OnBeforeExecute := HTTPRIOBeforeExecute;
FEPS_HTTPRIO.OnAfterExecute := HTTPRIOAfterExecute; <-- Error line
end;
procedure TMosquitoShield.HTTPRIOBeforeExecute(const MethodName: string;
var SOAPRequest: WideString);
var
tmpString: TStringList;
begin
try
SOAPRequest := StringReplace(SOAPRequest,'<ReversalType>_Application','<ReversalType>Application',[RfReplaceAll]);
SOAPRequest := StringReplace(SOAPRequest,'<ReversalType>_System','<ReversalType>System',[RfReplaceAll]);
SOAPRequest := StringReplace(SOAPRequest,'<CardholderPresentCode>NotPresent2','<CardholderPresentCode>NotPresent',[RfReplaceAll]);
SOAPRequest := StringReplace(SOAPRequest,'<DeviceInputCode>NotUsed3','<DeviceInputCode>NotUsed',[RfReplaceAll]);
except
on ER : ERemotableException do
ShowMessage(ER.ClassName + ' error raised, with message : ' + ER.FaultDetail + ' :: '
+ ER.Message);
on E : Exception do
ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message);
end;
end;
procedure TMosquitoShield.HTTPRIOAfterExecute(const MethodName: string;
var SOAPResponse: TStream);
var
tmpString: TStringList;
begin
try
tmpString := TStringList.Create;
SOAPResponse.Position := 0;
tmpString.LoadFromStream(SOAPResponse);
tmpString.Text := StringReplace(tmpString.Text,'Application','_Application',[RfReplaceAll]);
tmpString.Text := StringReplace(tmpString.Text,'System','_System',[RfReplaceAll]);
tmpString.Text := StringReplace(tmpString.Text,'<PASSUpdaterOption>Null','<PASSUpdaterOption>Null2',[RfReplaceAll]);
tmpString.Text := StringReplace(tmpString.Text,'<TransactionSetupMethod>Null','<TransactionSetupMethod>Null3',[RfReplaceAll]);
tmpString.Text := StringReplace(tmpString.Text,'<Device>Null','<Device>Null4',[RfReplaceAll]);
tmpString.Text := StringReplace(tmpString.Text,'<ConsentCode>NotUsed','<ConsentCode>NotUsed2',[RfReplaceAll]);
tmpString.Text := StringReplace(tmpString.Text,'<DeviceInputCode>NotUsed','<DeviceInputCode>NotUsed3',[RfReplaceAll]);
SOAPResponse.Position := 0;
tmpString.SaveToStream(SOAPResponse);
except
on ER : ERemotableException do
ShowMessage(ER.ClassName + ' error raised, with message : ' + ER.FaultDetail + ' :: '
+ ER.Message);
on E : Exception do
ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message);
end;
end;
非常感謝!不知道如何添加到該方法。 – BrianKE 2013-04-24 13:49:42
+1提醒我單位名稱前綴;我前段時間遇到了同樣的「保留名稱」問題,並使用_技巧,但您的解決方案更好。 – 2013-04-24 14:57:35