使用Delphi 2005,我创建了一个测试应用程序(使用TForm)来测试SOAP API。不幸的是,这个API已经声明了Delphi保留的一些枚举(应用程序,系统和终端)。我在SOAP文件(_Application,_Terminal和_System)中重命名了枚举,并且能够编写OnBeforeExecute和OnAfterExecute方法,在提交前后用原始名称替换这些重命名的枚举。
我现在正在尝试将其合并到我的大型项目中,并希望在类文件(无表单)中捕获此SOAP API的所有代码。使用我的测试器应用程序,我在表单中添加了一个THTTPRIO对象(来自Tool Palette),并且可以在Object Inspector中轻松设置OnBeforeExecute和OnAfterExecute方法。现在使用类(TComponent)我不能像使用表单一样使用Tool Palette添加THTTPRIO对象。我试图通过代码创建THTTPRIO对象但是出现了一些错误。
我在E2009 incompatible types: 'Parameter lists differ'
上收到错误FEPS_HTTPRIO.OnAfterExecute := HTTPRIOAfterExecute;
(请参阅下面的代码)
为什么我会在FEPS_HTTPRIO.OnBeforeExecute := HTTPRIOBeforeExecute;
上得到错误,而不是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;
,我怎样才能在班上实现这两种方法?
以下是我通过代码创建THTTPRIO的方法:
{{1}}
答案 0 :(得分:4)
您的方法签名必须与事件类型的签名完全匹配。在var
方法的SOAPResponse
参数之前移除HTTPRIOAfterExecute
。
对于您描述的名称冲突,您可以通过在代码元素(枚举成员,变量,类型等)前加上单位名称前缀来避免它们:SOAP_API.Application
- 用于SOAP枚举,而Forms.Application
用于德尔福Application
全球。