[英]Convert a snippet of Delphi code to C++Builder
I am working with the EurekaLog bug catcher for Delphi/C++Builder. 我正在使用Delphi / C ++ Builder的EurekaLog错误捕捉器。 All of their examples are in Delphi and I am using C++Builder.
他们所有的示例都在Delphi中,而我正在使用C ++ Builder。 The Delphi code below is one of their examples that causes a software exception.
下面的Delphi代码是导致软件异常的示例之一。 I tried to convert this into C++ below but my code is wrong.
我试图在下面将其转换为C ++,但是我的代码是错误的。 Can you show me the correct C++ Code to make this work.
您能告诉我正确的C ++代码来完成这项工作吗?
Delphi code from EurekaLog EurekaLog的Delphi代码
type
EMyException = class(Exception);
Procedure TForm. ButtonClick(Sender: TObject);
begin
raise EMyException.Create('Error Message');
end;
end.
My C++Builder code that does not work 我的C ++ Builder代码不起作用
typedef class{
Exception;
}EMyException;
void __fastcall TForm1::ButtonClick(TObject *Sender)
{
throw new EMyException("Error Message");
}
You need to derive a new class, not use a typedef. 您需要派生一个新类,而不使用typedef。 And don't use
new
when calling throw
(this is the only area in C++Builder where a TObject
descendant must not be constructed with new
). 不要使用
new
调用时throw
(这是C ++ Builder中的唯一的地方一个TObject
后代不能以构建new
)。
class EMyException : public Exception
{
public:
__fastcall EMyException(const String Msg) : Exception(Msg) {}
};
void __fastcall TForm::ButtonClick(TObject *Sender)
{
throw EMyException("Error Message");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.