我想在全局范围内声明一个TBitmap。
我尝试的方法如下:
在方法的局部范围内,这可以很好地工作
std::auto_ptr<Graphics::TBitmap> RenderGraphic(new Graphics::TBitmap());或
Graphics::TBitmap * RenderGraphic = new Graphics::TBitmap;因此,为了全局声明它,我在头文件中尝试这样做
Graphics::TBitmap *RenderGraphic;这是在构造函数中的
__fastcall TShipGraphic::TShipGraphic(TComponent* Owner)
: TForm(Owner)
{
Graphics::TBitmap * RenderGraphic = new Graphics::TBitmap;
}编译得很好,但在运行时,会在第一次出现
RenderGraphic->Canvas->Pen->Color = clBlack;请提前告知,谢谢。
我使用的参考源是C++ Builder Graphics Introduction
它建议在构造函数中声明
发布于 2018-11-12 21:09:45
你需要实现一个单例。考虑只读的情况(位图只创建一次,没有setter函数)。
在MyGraphics.h中定义存取器函数
#include <vcl.h>
TBitmap* GetRenderGraphic();在MyGraphics.cpp中实现
static std::unique_ptr<TBitmap> renderGraphic(new TBitmap());
TBitmap* GetRenderGraphic()
{
return renderGraphic.get();
}使用它(需要包括MyGraphics.h)
GetRenderGraphic()->Canvas->Pen->Color = clBlack;https://stackoverflow.com/questions/53259456
复制相似问题