iT邦幫忙

0

TMask在C++Builder v12.2及v13有差異的解決方法

  • 分享至 

  • xImage
  •  

我使用 Embarcadero C++ Builder. 發現了system.masks.hpp內之TMask在v12.2與最新版本v13有不同處。

在v12.2 TMask僅用一個參數
__fastcall TMask(const System::UnicodeString MaskValue);

而在v13 TMask改成用兩個參數
__fastcall TMask(const System::UnicodeString MaskValue, bool CaseSensitive);

那該如何使程式碼在新舊版編譯呢? 解法是使用C語言條件編譯 #if、#else、#endif。

//------- after BCB6, using unique_ptr ----
String pattern=Edit1->Text.Trim();
String input=Edit2->Text.Trim();

std::unique_ptr mask;

#if (CODEGEARC >= 0x0780) // 判斷版本, V13(含)之後
  mask.reset(new TMask(pattern, true));
#else
  mask.reset(new TMask(pattern));
#endif

bool chk = mask->Matches(input);

//---------- BCB6 -------------------------
String pattern=Edit1->Text.Trim();
String input=Edit2->Text.Trim();

TMask *mask;

#if (CODEGEARC >= 0x0780) // 判斷版本, V13(含)之後
  mask = new TMask(pattern, true);
#else
  mask = new TMask(pattern);
#endif

bool chk = mask->Matches(input);

delete mask;
//-----------------------------------------

在很久已前我就看過#if #else #endif這種用法。今日遇此問題,用了它解決了,才算真瞭解了。


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言