19. 檢視 DLL 提供的函式 E:\WINNT\system32>dumpbin /exports user32.dll Microsoft (R) COFF Binary File Dumper Version 5.00.7022 Copyright (C) Microsoft Corp 1992-1997. All rights reserved. Dump of file user32.dll File Type: DLL Section contains the following Exports for USER32.dll 0 characteristics 336A2A2A time date stamp Sat May 03 01:53:46 1997 0.00 version 1 ordinal base 634 number of functions 634 number of names ordinal hint name 1 0 ActivateKeyboardLayout (00015B1A) 2 1 AdjustWindowRect (0000D704) 3 2 AdjustWindowRectEx (00007D8E) 4 3 AnyPopup (00043ABB) 5 4 AppendMenuA (00011F57) 6 5 AppendMenuW (0002D7A4)
33. C++Builder Overview Rapid Application Development tools Stand-alone executables, with no run-time libraries required to distribute applications Fully object-oriented, with a well respected and rock solid base Inherent database connectivity through the Borland Database Engine Painless upsizing from local databases to client/server databases
38. Form Designer Configuring the Form Designer Creating a simple form Adding components to a form Moving and resizing components on a form A simple example of a form
39. Code Editor IDE-managed section Auto declared/cleared event-handlers Useful Hotkeys Bookmarking (Ctrl-Shift-<digit> to mark, Ctrl-<digit> to jump Ctrl-K-U, Ctrk-K-I for unindent, indent Ctrl-Shift-UP, Ctrl-Shift-Down for jumping between declaration and implmeneation Ctrl-Shift-C to help you finish the class declaration Ctrl+Enter to fast open files Ctrl-Shift-G to generate GUID (UUID)
40. The simplest event-handler Event handler (事件處理方法) 回應訊息或事件的函式 事件處理方法與一般成員函式( member function )並無二異 void __fastcall TForm1::Button1Click(TObject *Sender) { Close(); }
41. Project, Unit and Forms What makes up a project in C++Builder How to invoke and use the project manager The basic file types used by C++Builder how units and forms are related The CPP project and MAK file CPP unit and DFM files How to set project options The steps involved in compiling and linking a C++Builder project
42. The file types used by C++Builder BPR MAK CPP 、 OBJ DFM RES H 、 HPP DSK 、 DOF ILC 、 ILD 、 ILF PAS 、 DCU
44. Using the components Placing components on forms Visual & non-visual components Component relations Naming convention Copy & paste Group select Resizing & alignment Shared event-handler
45. Visual & Non-Visual Components Visual components Visible at both design-time and run-time Have Left 、 Top 、 Width 、 Height properties Have Show 、 Hide methods Have Owner and Parent property Non-visual components Visible only at design-time Encapsulate functionality only Do not have Parent property
51. Multi-Appearance of Forms object Form1: TForm1 Left = 341 Top = 337 Width = 148 Height = 179 Caption = 'Form1' ... object Button1: TButton Left = 32 Top = 16 ... end object Button2: TButton Left = 32 Top = 56 ... end object Button3: TButton Left = 32 Top = 96 ... end end = =
52. Using the form What’s MainForm ? Form properties Border Icons Border Style Form Style Window State Auto-Create & Available forms Dynamically create form Show / ShowModal methods Show just pop-ups the form ShowModal will not return till the from close
53. Create Form On Demand Reuse the auto-created form 若 form 時常使用 若 form 上的資訊必須維持,且不方便另外儲存 Create form on demand 不一定會使用到的 form 不只建立單一副本,可能建立多重副本的 form void __fastcall TForm1::Button1Click(TObject *Sender) { AboutBox->ShowModal(); } void __fastcall TForm1::Button1Click(TObject *Sender) { TAboutBox* box = new TAboutBox(this); box->ShowModal(); delete box; }
54. Modalless and Modal Form Modalless form 一般的 form Form 顯示後,程式會繼續執行 必須呼叫 Close 方法關閉 Modal form 對話盒 擁有自己的訊息迴圈 Form 關閉前,程式不會繼續執行 只要按鈕的 ModalResult 屬性不為 mrNone , form 就會自動關閉
55. C++ Language The evolution of programming paradigm The definition of object-oriented programming Why object-oriented programming ? The C++ programming language
56. Programming Paradigm How we think and write programs ? program domain problem domain The evolution: procedural programming modular programming ADT programming object-oriented programming generic programming
57. Procedural Programming Paradigm FORTRAN, C, Pascal There are many procedures (operations) Data is placed at global areas or inside procedures Procedures are designed to process data Program = data + procedures which process the data
58. ADT Programming Paradigm CLU, Ada, Module-2 ADT (abstract data types) programming is also called object-based programming Encapsulate operations and data inside objects Program = objects and their interactions
59. Object-Oriented Programming Paradigm Simula, Smalltalk, Java 以繼承 (inheritance) 和動態繫結 (dynamic binding) 擴充了 ADT 繼承 : 既有實作碼的重複運用 動態繫結 : 既有之公開介面的重複運用 C++ is a mixed-paradigm programming language
64. C++ 的由來 西元 1980 年, Bjarne Stroustrup 發明了 "C with Classes" 語言,因為他想為 C 語言加入如同 Simula67 語言般的事件驅動機制。直到 1983 年夏天,才由 Rick Mascitti 創造出 C++ 這個語言名稱。
65. 如何看待 C++ ? 如果你懂得 C 語言,那麼可以這樣看待 C++ 語言: 它是比較好的 C 語言 它提供資料抽象化機制 它支援物件導向程式設計,所提供的語法及字眼讓你可以很輕易地將物件導向精神落實到 C++ 程式中 C++ 語言的功能強大,無庸致疑, template 、 exception handling 、 RTTI 、 Standard Library 等等功能不斷地加強翻新。由於使用者眾,要求必多,期望必高,再加上 C++ 本身定位在功能強大範圍廣泛的通用性語言,如江海之納百川, C++ 自然日益複雜。
66. 強大複雜的 C++ 著名的雜誌 C++ Journal 上曾有段話: 雖然是最流行的物件導向程式語言,但除非你有足夠的耐心及精神來全盤掌握它,否則輕易嘗試的後果可能只會得到一臉的挫折。當然囉,十分的複雜也帶來十分的便利及高度的成就感及樂趣,端視你如何取捨。 如果你認為 C++ 還不算太複雜,那麼請你解釋何謂 protected abstract virtual base pure virtual private destructor ,而你又會在何時需要它呢? Tom Cargill C++ Journal Fall 1990
67. 強大複雜的 C++ 並不是語言中的每一項特質都要成你的下一座攀爬目標。究竟要不要使用某項性質 , 我們應該以程式的邏輯做決定 , 而不是只因為它在那裡。 -- C++ Primer
68. C++ 類別宣告 使用 class 關鍵字。 類別裡可以加入任意數目的變數及函式宣告。 建構函式與類別名稱相同。 解構函式為類別名稱前頭加上 ~ 。 class TMyClass { int a, b, c; TMyClass(<parameters>); // 建構函式 ~TMyClass(void); // 解構函式 void draw(); int draw(int x, int y, int z); };
70. TMammal 類別 TCat 及 TDog 類別 TMammal and child classes class TMammal { private : AnsiString FName, FEyeColor; int FAge; public : __fastcall TMammal( void ); virtual void __fastcall Speak( void ) = 0; }; class TCat : public TMammal { virtual void __fastcall Speak( void ) {ShowMessage(“I’m Cat”);} }; class TDog : public TMammal { virtual void __fastcall Speak( void ) {ShowMessage(“I’m Dog”);} };
71. 在累堆建立 TCat 及 TDog 物件 呼叫 TMammal 類別宣告的 Speak 函式 由於多型機制,兩個物件呈現不同的結果 The Power of Polymorphism void __fastcall TForm1::Button1Click(TObject *Sender) { TMammal* Mammal = new TCat (); Mammal->Speak(); delete Mammal; } void __fastcall TForm1::Button2Click(TObject *Sender) { TMammal* Mammal = new TDog (); Mammal->Speak(); delete Mammal; }
72. C++ Enhancement for BCB The new keywords adds to C++Builder New class scoping options in C++Builder How C++Builder includes DFM resources in projects How to use open arrays in C++Builder How to handle VCL exceptions How to throw VCL exceptions How to create your own custom VCL exceptions
73. Added Keywords New access specifier for classes __published __fastcall modifier for methods
76. AnsiString Class and Variant AnsiString 方便好用的字串 不必操心記憶體配置問題 c_str() member function reference count Variant void __fastcall TForm1::Button1Click(TObject *Sender) { Variant x; x = 13; edtTest->Text = IntToStr( x + 12 ); x = "Hello, world"; ShowMessage( x ); }
77. Set To create a set, you must supply three template parameters. 例如: typedef Set <char, 'A','Z'> UPPERCASESet; UPPERCASESet s;
93. 程式實作 – Other Possibilities Connect to SMTP server and send mail directly. HTTP resources grabber (+ regular expression parser library) ... Please give your suggestions.
103. 學習 VCL 類別架構 由於物件導向的繼承特性,類別庫(也就是包含一大堆類別的程式庫)比起一般的函式庫還要好記、好學。 假設我知道下列幾件事實: 我知道 TComponent 是元件的始祖,有 Name 及 Tag 兩個屬性。 我知道 TControl 是可視元件的始祖,有 Left 及 Right 兩個屬性,有 Show 及 Hide 兩個方法。 我知道 TButton 是元件,而且是看得見的元件,所以它一定是 TControl 類別的後代,也是 TComponent 類別的後代,因為 TControl 繼承自 TComponent 。 那麼,就可以歸納出結論- TButton 一定有 Name 、 Tag 、 Left 、 Right 四個屬性,也一定有 Show 及 Hide 兩個方法可用。
134. Creating Database Application C++Builder model for database access How to use Table and TDataSource components How to use data-aware components How to create a simple data entry and database browser How to create a master/detail form
135. Connecting to Database in C++Builder Dataset objects, DataSource components, and Data-aware controls relationships
136. Using the Database Explorer Manipulating Aliases Viewing Data Creating Database Form
137. Using the Database Desktop Alias Manager Table Structure Field Name Field Type Field Size Primary Key, Second Indexes Utilities Add, Copy, Empty, Sort ...
138. Using Database Wizards When to use Database Wizards and how they can help you How to invoke the Database Form Wizard How to use the Database Form Wizard to create a simple data entry form How to use Data Modules in your applications How to use the Form Wizard to create a master/detail form
139. Creating a Database Form - Step by Step Dataset objects TTable, TQuery, TStoredProc DataSource objects TDataSource Data-aware objects TDBNavigator TDBGrid, TDBEdit, TDBListbox, etc
140. TTable and TDataSource TTable component Database property TableName property IndexName vs IndexFieldNames Various events TDataSource compnent DataSet property AutoEdit property
141. Understanding Fields The definition of fields How to change a field description How to remove a field from Grids and Tables Formatting fields Making calculated fields Lookup fields Validation field data
142. The Field Property Editor DisplayLabel property DisplayWidth property Index property
144. Manipulating the DataSets Data navigation Filtering data with SetRangeStart and SetRangeEnd Filtering data with the Filter property Finding records Bookmarking records Providing default values
145. Data Navigating Activity Open, Close Navigating First, Prior Next, Last MoveBy Bof, Eof Modify Edit, Insert, Append Post, Cancel
146. Limiting Record Sets SetRange Method High performance but only used on indices SetRangeStart SetRangeEnd ApplyRange CancelRange Filter Slow but flexibility
148. Bookmarking Records void DoSomething (const TTable *Tbl) { TBookmark Bookmark; Bookmark = Tbl->GetBookmark(); //Allocate memory and assign a value Tbl->DisableControls(); // Turn off display of records in data controls try { Tbl->First(); // Go to first record in table while (!Tbl->Eof) // Iterate through each record in table { // Do your processing here ... Tbl->Next(); } } catch(...) { Tbl->GotoBookmark(Bookmark); Tbl->EnableControls(); // Turn on display of records in data controls, Tbl->FreeBookmark(Bookmark); // Deallocate memory for the bookmark } }
151. 例外處理機制 傳統錯誤判斷方法: Dirty, inconvenient and easily generate mistakes. GetMem(pBuffer, 1000); if (pBuffer = nil) then begin /* error processing code here; */ end; // 取得 x, 計算 x 的倒數 if x = 0 then begin /* error processing code here; */ end;
152. 例外處理機制 例外處理方式: 讓例外狀況的處理動作不影響正常流程。 try edtTotal.Text := IntToStr( StrToInt( edtOp1.Text ) / StrToInt( edtOp2.Text ) ); except on EDivByZero do ShowMessage( ' Cannot divide by zero ' ); on EConvertError do ShowMessage( ' Error during conversion ' ); end;
153. 例外處理機制 主動丟出例外: 將例外狀況集中處理。 try if numItems = 0 then raise EDivByZero.Create( ' Cannot divide by zero ' ) // ^ throw your own exception else edtAvg.Text := FloatToStr( sum / numItems ); except edtAvg.Text := FloatToStr(0.0); raise; // <- re-throw the same exception end;
169. 參考書目 - C / C++ Programming The C Programming Language Brian W. Kernighan / Prentice Hall The C++ Programming Language Bjarne Stroustrup / Addison Wesley C++ 程式語言經典本 / 葉秉哲 / 儒林 C++ Primer Stanley B. Lippman, Josee Lajoie, Jose Lajoie / Prentice Hall C++ Primer 中文版 / 侯捷 / 碁峰
170. 參考書目- Delphi / C++Builder Delphi 學習筆記 Win32 基礎篇 錢達智 / 碁峰 Delphi 深度歷險 / C++Builder 深度歷險 陳寬達 / 碁峰 Secrets of Delphi 2 Ray Lischner / Waite Group Delphi Component Design Danny Thorpe / Addison Wesley C++Builder 4 Unleashed Charlie Calvert / SAMS
171. 參考書目 - Windows Programming Programming Windows Charles Petzold / Microsoft Press Programming Applications for Microsoft Windows Jeffrey Richter / Microsoft Press Windows 95: A Developer’s Guide Jeffrey Richter, Jonathan Locke / M&T Books Windows 95 程式設計指南 / 李書良譯 / 碁峰 Multithreading Applications in Win32 James Beveridge, Robert Wiener / Addison Wesley Win32 多緒程式設計 / 侯俊傑譯 / 碁峰
172. 參考書目- OOA / OOD / OOP Object-Oriented Analysis and Design with Applications, 2 nd Ed. Grady Booch / Benjamin/Cummings Publishing Object-Oriented Modeling And Design James Rumbaugh, etc. / Prentice Hall Object-Oriented Software Construction 2 nd Ed. Bertrand Meyer / Prentice Hall Design Patterns, Elements of Reusable Object-Oriented Software GoF / Addiseon Wesley 物件導向設計模式 / 葉秉哲 / 培生
173. 參考書目- Practical Programming Programming Pearls 2 nd Ed. Jon Bentley / Addiseon Wesley The Practice of Programming Brian W.Kernighan, Rob Pike / Addiseon Wesley Write Solid Code Steve Maguire / Microsoft Press 如何撰寫0錯誤程式 / 施威銘研究室 / 旗標
174. 參考書目- 工具書 Win32 Programming Brent Rector, Joseph Newcomer / Addison Wesley Delphi Programming Problem Solver Neil Rubenking / IDG Books Delphi 2 高階技巧 / 劉剛樑譯