C++Builder 日常開發實用技巧彙整
1. 編輯器快捷鍵
| 操作 | 快捷鍵 |
| 整塊向右縮排 | Ctrl+Shift+I |
| 整塊向左縮排 | Ctrl+Shift+U |
2. 取得執行檔所在目錄
ExtractFileDir(Application->ExeName);
3. 迴圈中保持介面回應
Application->ProcessMessages();
4. DLL 匯出函數標準宣告
extern "C" __declspec(dllexport) __stdcall __int32 Fun(__int32 n32_i);
5. DLL 匯入函數標準宣告
extern "C" __declspec(dllimport) __stdcall __int32 Fun(__int32 n32_i);
6. DLL 除錯設定
Run | Parameters 中填入呼叫該 DLL 的 *.exe 路徑。
7. 開啟 CHM 說明檔
ShellExecute(NULL, NULL, L"HelpFile.chm", NULL, NULL, SW_SHOWNORMAL);
8. PowerBuilder ↔ C/C++ 資料類型對照表
| Microsoft | PB (16-bit) | PB (32-bit) |
| Bool | Boolean | Boolean |
| Byte, Char | Char | Char |
| Char* | Ref String | Ref String |
| Colorref | Uint | Ulong |
| Double | Double | Double |
| Dword | Uint | Ulong |
| Handle/Hdc/Hfile/Hinstance/Hwnd | Uint | Ulong |
| Int | Int | Int |
| Long | Long | Long |
| Lparam/Lpbyte/Lpdword/Lpint/Lpstr/Lpcstr/Lpvoid/Lpword | Ref Int/Struct | Ref Long/Struct/Ulong |
| Short | Int | Int |
| Structure | Ref Struct | Ref Struct |
| Uint | Uint | Uint |
| Void** | SUBROUTINE | SUBROUTINE |
| Word | Int | Long |
| Wparam | Uint | Ulong |
9. CodeGuard 記憶體洩漏偵測
- 專案選項:
Project | Options | CodeGuard
- 支援庫:
CG32.LIB / CG32.DLL
10. MFC 執行階段庫常見 DLL
mfc42.dll, MFC42D.DLL, MFCD42D.DLL, MFCN42D.DLL
MFCO42D.DLL, MSVCP60.DLL, MSVCP60D.DLL
MSVCRTD.DLL, NTDLL.DLL
11. ADO 資料庫連線測試
- 建立空白檔案
TestDataBase.udl
- 雙擊開啟,依嚮導設定連線
12. 編譯器關鍵設定
| 分頁 | 關鍵選項 |
| Compiler | Full debug、Code optimization=None、Debug information、Line number information、Disable inline expansions |
| Linker | Create debug information、Don't generate state files、Use dynamic RTL |
| Directories/Conditionals | Debug source path = $(BCB)\source\vcl |
| Packages | **除錯時關閉** Build with runtime packages |
13. RTL 執行階段庫切換
修改 *.bpr 專案檔:
// 多執行緒靜態連結(含 VCL)
<CFLAG1 value="-tWD -tWM -Od -H=$(BCB)\lib\vcl50.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c"/>
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cw32mt.lib"/>
// 單執行緒靜態連結(無 VCL)
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib"/>
14. CodeGuard 除錯器操作
- 編譯:
Project | Options | CodeGuard
- 執行設定:
Tools | CodeGuard Configuration
- 日誌檔:
*.CGI,用 View | Debug Windows | CodeGuard Log 或記事本檢視