DELPHI:在TComponent中声明HTTPRIO.OnBeforeExecute
使用Delphi2005,我创建了一个测试应用程序(使用TForm)来测试SOAP API。不幸的是,这个API声明了一些由Delphi保留的枚举(应用程序、系统和终端)。我重命名了SOAP文件(_应用程序、_终端和_系统)中的枚举,并且能够编写onbeforecute和onafterecute方法,以在提交前后用原始名称替换这些重命名的枚举 我现在正试图将其合并到我更大的项目中,并希望在一个类文件(无格式)中捕获此SOAP API的所有代码。使用我的tester应用程序,我在表单中添加了一个THTTPRIO对象(从工具选项板),可以在对象检查器中轻松设置onbeforecute和OnAfterExecute方法。现在使用类(一个TComponent),我不能像使用表单那样使用工具选项板添加THTTPRIO对象。我试图通过代码创建THTTPRIO对象,但出现了一些错误 我在DELPHI:在TComponent中声明HTTPRIO.OnBeforeExecute,delphi,soap,delphi-2005,Delphi,Soap,Delphi 2005,使用Delphi2005,我创建了一个测试应用程序(使用TForm)来测试SOAP API。不幸的是,这个API声明了一些由Delphi保留的枚举(应用程序、系统和终端)。我重命名了SOAP文件(_应用程序、_终端和_系统)中的枚举,并且能够编写onbeforecute和onafterecute方法,以在提交前后用原始名称替换这些重命名的枚举 我现在正试图将其合并到我更大的项目中,并希望在一个类文件(无格式)中捕获此SOAP API的所有代码。使用我的tester应用程序,我在表单中添加了一个T
FEPS_HTTPRIO.OnAfterExecute:=HTTPRIOAfterExecute上得到错误E2009不兼容类型:“参数列表不同”
代码>(参见下面的代码)
为什么我会在这个问题上得到错误,而不是在FEPS_HTTPRIO.onbeforecute:=httpriobeforecute代码>以及如何在类中实现这两个方法
下面是我如何通过代码创建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;
单元c_MoSh;
接口
使用类、窗体、窗口、SysUtils、c_MoShAPI、InvokeRegistry、控件;
类型
TMoSh=类别(t组件)
私有的
...
过程httpriobeforecute(const MethodName:string;
var SOAPRequest:WideString);
过程HTTPRIOAfterExecute(const MethodName:string;
var(响应:TStream);
...
构造函数TMoSh.Create();
开始
FEPS_HTTPRIO:=THTTPRIO.Create(self);
FEPS_HTTPRIO.onbeforecute:=httpriobeforecute;
FEPS_HTTPRIO.OnAfterExecute:=HTTPRIOAfterExecute 方法签名必须与事件类型的签名完全匹配。在HTTPRIOAfterExecute
方法中删除var
beforeSOAPResponse
参数
对于您描述的名称冲突,您可以通过在代码元素(枚举成员、变量、类型等)前面加上单元名称来避免它们:SOAP\u API.Application
-对于SOAP枚举,和Forms.Application
对于DelphiApplication
global.您的方法签名必须与事件类型的签名完全匹配。在HTTPRIOAfterExecute
方法中删除var
beforeSOAPResponse
参数
至于您描述的名称冲突,您可以通过在代码元素(枚举成员、变量、类型等)前面加上单元名称来避免它们:SOAP\u API.Application
-用于SOAP枚举,而Forms.Application
用于Delphi应用程序
全局。非常感谢!不知道这是怎么添加到方法中的。+1用于提醒我单位名称前缀;不久前,我遇到了相同的“保留名称”问题,并使用了uu技巧,但您的解决方案更好。非常感谢!不知道这是怎么添加到方法中的。+1用于提醒我单位名称前缀;不久前,我遇到了相同的“保留名称”问题,并使用了uu技巧,但您的解决方案更好。