简体   繁体   中英

Convert a snippet of Delphi code to C++Builder

I am working with the EurekaLog bug catcher for Delphi/C++Builder. All of their examples are in Delphi and I am using C++Builder. The Delphi code below is one of their examples that causes a software exception. I tried to convert this into C++ below but my code is wrong. Can you show me the correct C++ Code to make this work.

Delphi code from EurekaLog

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

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. 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 ).

class EMyException : public Exception
{
public:
    __fastcall EMyException(const String Msg) : Exception(Msg) {}
};

void __fastcall TForm::ButtonClick(TObject *Sender)
{
    throw EMyException("Error Message");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM