A c ++ programmer's Delphi Study Notes
To put it bluntly, there are some developers who are not familiar with Delphi in the position of a C ++ programmer. Just a few weeks ago, I wrote an article to maintain the dignity of C ++. For various reasons, today I have to learn about Delphi and be familiar with Delphi.
I gave myself 15 days to learn a language? I chose "Delphi from getting started to proficient" and "Delphi Advanced Development Guide" from Marco Cantu as my learning book. The first book is "from entry to mastery", but if you are not familiar with an OOP language, this book is not suitable for you. It is appropriate for me. The total thickness of the second book is one thousand five hundred pages. Well, it's about one hundred pages a day. I hope I can do it myself.
I decided to write down my thoughts and confusions as my memories of entering the new field, and hoped to provide some help to those who are on the same journey.
I. Environment
"To do well, you must first sharpen the tool." It is very important to be familiar with the development environment. Unlike the MDI interface of VC, Delphi adopts multiple independent forms. Does this indicate that Borland prefers peer-to-peer interaction between components? I secretly guessed it.
1. The desktop setting can be separated from the project, and the desktop setting takes precedence over the project setting.
2. the to-do list is a good tool for reminding yourself or others.
3. appbrowser is similar to the main interface of VC. Symbol prompts and code completiont are also provided. Well, there is a class completion not available in VC, which can be automatically completed between the declaration and implementation.
4. The concept of Project Group is a bit like Solution on the. net platform, but. net is multilingual.
2 Language
The core of Delphi is the VCL library, which is based on Object Pascal. The article "Object" is detailed in two chapters, from entry to mastery, but it does not mention "Pascal ". Well, I remember it.
1. Use is used to reference external units. Unlike header files, Use does not pass.
2. Delphi uses the reference object model. The object variable only holds the object reference and does not hold the object itself. All objects are manually allocated from the heap.
3. The encapsulation of Delphi is strange. The access permission setting of class members only takes effect outside the unit. In a unit, you can use any external metadata class private member. My friend explained that it is equivalent to a friend of C ++. In fact, there is a big difference in my thoughts-must friendship be two-way? (If the Unit method is used as A friend, A can access B, and B can certainly access A.) is friendship passed? (Using the Unit method as A friend, A can access B, B can access C, and A can certainly access C ). In my opinion, this concept of friendship is incompatible. I hope one day I can understand the design considerations of Delphi.
4. After declaring the object variables, the actual generation of the Delphi object must call the constructor. The constructor is a special class method that inherits from TObject and can be overloaded. The class method is used to construct an object without keywords. I think this is a special use of single inheritance.
5. There is an example of dynamically creating TButton in the book. Creat is used to create an object, but no Free explicit release is used.
. I suspect that memory leakage will occur. I think it is up to the TForm container holding TButton to release it. My friend confirmed my idea. Delphi avoids the trouble of manually releasing memory.
6. the keywords of Delphi are annoying, long and many, and there are many places to be typed. The advantage is that it can provide more information for the compiler to identify errors and speed up compilation.
7. Because of the reference object model, direct object access in C ++ does not have polymorphism, And the polymorphism mechanism only works under pointers and references.
8. Point out the events that can be handled using the message directly. Alas, it reminds me of the similar extension of Borland to the c ++ language in OWL.
9. A large amount of dynamic type conversion is a feature of Pascal?
10. form inheritance. It seems that even the control attributes can be inherited.
11. Very strange design. There are class methods, but they do not provide class variables. You need to simulate them with Unit-level variables.
12. If I guess it is good, the control's Events should be "Object method Pointer ".
13. Powerful mechanism: Class references can dynamically create different data types in the same form. Similar capabilities in C ++, afraid to use the Builder mode.
14. Parameter objects are transmitted by reference and assigned by reference. Only the Assign method is provided for partial classification to copy objects. Alas, I miss the value semantics of C ++.
15. Finally block! Solved the issue of resource release that requires high skill in C ++. But why can't I use it with javast? Not quite clear.
16. attributes and events ?? A language tailored for VCL. In fact, attributes and events are not essential elements of object orientation.
17. I think the delegated model of VCL event processing is similar to that of JAVA. Only Java Listener can process multiple
Listener. It seems that Delphi can only process one event attribute? However, the processing speed is much faster.
18. a) inherit from the TComponent class, B) New constructor, c) Routine Register, d) install. The ease of creating VCL components is really touching.
19. The book says that VCL is better than ActiveX, because ActiveX does not have a full inheritance mechanism, and I do not agree. Aggregation is a mechanism selected prior to inheritance.
20. Interface, ugly !! I even doubt whether this is the Hejlsberg design. It seems like a language component that supports temporary patchwork for Com, not in coordination with the whole, like a foreign user. Interfaces are powerful, but poor design makes it a pain to use. Except for COM and multi-inheritance, I think no one is willing to use it.
Object Pascal gives me a deep image. Next, we should learn about VCL and see how Borland assembles the components of this language into a powerful tool for development. (Coming soon)