Preface: Currently, I am writing a book for skilled Delphi programmers on the topic of building well-designed programs using object-oriented programming techniques in Delphi.
This book is still in the process of being written. I hope that everyone can have a preliminary understanding of the theme and language style of this book. At the same time, you can put forward your own opinions. As an author, I hope this book can become a classic among domestic original Delphi books. It may not succeed, but I will try my best.
Due to the above reasons, it is impossible for me to post the entire book (haha, then no one will buy it), so there should be no subsequent chapters posted here (maybe there will be some excerpts).
Here, I would like to thank those friends who have encouraged me and provided opinions (I posted it on the Delphi forum of csdn and received a wide range of responses, thank you all). I would also like to thank my girlfriend, Esan, who has always supported and inspired me. All I can do is to write well and repay everyone. I know that everyone (including me) has been waiting too hard for a good book!
Chapter 1 Re-understanding Delphi
Simplicity is the hardest thing in the world to obtain: it is the ultimate limit of experience and the ultimate goal of genius. ——George Sand You are already a skilled Delphi programmer and can use Delphi to quickly write a beautiful and practical program; you love Delphi; she has become an indispensable part of your work and study. I assume that these are true, then you must have your own reasons or reasons for choosing Delphi as your first choice development tool. At least, I meet all the above assumptions. Now, what I want to share with you is the reasons and reasons why I chose Delphi, as well as my understanding of Delphi. You can regard me as a fanatic who supports Delphi, although that will make me feel that you view me too superficially. I don't admit it, but I don't mind. Because, I really love her. The version of Delphi I first came into contact with was 3.0. At that time, I just used it as a RAD tool like Visual Basic. However, as time goes by, Delphi 3, Delphi 4, Delphi 5, Delphi 6 and Kylix have a deeper and deeper understanding of Delphi. It is a tool with rich connotations. The more people understand her, the more they become obsessed with her and the more they feel inseparable from her, although it is still just a tool. Pascal is a language that pays attention to program aesthetics - there is no doubt that Pascal code is the most beautiful code - Delphi based on Object Pascal (a Pascal language that supports object-oriented) takes this beauty to the extreme. Now, you can open Delphi, select "Help"-"About" menu, when the About window appears, hold down the Alt key and type "team" sequentially at the same time. What do you see? Yes, the list of Delphi developers, let us thank them for creating such development tools that are more like works of art!
1.1 The "people-oriented" theory of development tools
You can often see questions like this on various programming forums: "Does VB still have a future?"; "Is Delphi going to be eliminated?"; "Is MFC going to be replaced by .NET?"... In fact, these When the question was raised, no one could give an answer. Because the future of a technology or a product is not entirely determined by the technology itself, but is also related to factors such as market demand and the development direction of the producing company. And what we should be concerned about are the answers to these questions? I think not. We know that everything in the world is composed of atoms; ever-changing programs are ultimately composed of three structures: sequence, loop, and branch; both VC's MFC and Delphi's VCL are built with object-oriented technology (regardless of the degree of object-oriented ). When you look past the superficial appearance of things, what you see is the same or similar essence! After mastering the essence, you will find that the manifestation of appearance is so natural. Just imagine, when you can peel off MFC completely like Hou Jie (the author of "Introduction to MFC"), will you still worry about MFC being replaced by a certain framework? From this perspective, for a professional programmer, the concept of programming remains unchanged. There is a certain pattern in the process of discovering, analyzing, and solving problems. Once you master this pattern, different programming languages and different development environments will have something in common for you. I think C++ is something every professional programmer must master. Of course, this does not mean simply learning its syntax (you can even ignore the learning of some syntax), but learning object-oriented design and programming methods through C++. Because C++ is broad and profound, because C++ is omnipotent. In C++, you can learn all about object-oriented theory. After learning, you will be transformed by C++. Because controversial features that exist in object-oriented theory (such as multiple inheritance) are supported in C++. Only after you have mastered it can you make your own choice (for or against). After mastering the object-oriented theory, whether it is C++, Object Pascal, java or even C#, you will feel their similarities. Does that mean that there are no other differences between development tools (perhaps it should be called integrated development environments, but I will refer to them as development tools according to my habit below) except for the languages they support? Of course not. Development tools are tools that help you realize your ideas, which are superstructures built on basic ideas. The degree to which a development tool supports the concept you want to implement and the degree to which it simplifies the implementation process is the consideration of the development tool. Development tools for programmers are like weapons for soldiers. If the weapons are not handy, half of them will be defeated before the battle. I have always liked the advertising slogan of Nokia mobile phones: Technology is people-oriented! Yes, "people" are the basis, and the mission of tools is to help people achieve their goals faster and easier. Therefore, development tools should also be people-centered! As a programmer and the most direct user of development tools, I hope that the development tools I use can truly be my partners and assistants. It can bring me a sense of freedom and allow me to freely navigate the world of code. It can accommodate me and adapt to me instead of putting shackles on me! Today on the Windows platform, there are many development tools to choose from: Visual C++, Visual Basic, Delphi, C++ Builder, JBuilder... They are based on different programming languages and are loyal to the product concepts of different companies. From this perspective , the difference between them is very big. So what kind of development tools are excellent, considerate, and people-oriented? My standards are to meet the following four points: 1. Be able to simplify the problem to be solved and quickly implement it with a certain concept 2. Do not hide any details you want to know 3. Can ignore the details you do not want to know 4. Take the initiative to Are there development tools that meet the above four points that are suitable for programmers of different levels? My answer is: yes! That's Delphi! She simplified everything but never stopped me from seeking truth. You can complete tasks in the simplified VCL virtual world she constructed for you. You can also delve into the world of VCL to explore its mapping relationship with the real world (that is, the real interface of the Windows platform) and learn the design of its Framework. You can also extend that virtual VCL world to suit your needs. I feel lucky that such a development tool exists, and even more lucky that I can choose her and complete my work with her! (In reality, the programming language and development tools used in the project are often beyond your personal control and will be restricted by many factors. For example: the customer's hardware environment, operating system environment, development environment, the cost and licensing of development tools. Certificate, etc. Therefore, I am very lucky to be able to choose my favorite development tools for development work.) Learning object-oriented concepts through C++ and using Delphi to solve real-world problems is my approach. At the same time, it also verifies the saying: learn from difficult places and apply from easy places. Real programmers use C++, smart programmers use Delphi. Well, really smart programmers use C++ to understand Delphi!
1.2 More advantages of Delphi
I have used many mainstream development tools, why did I choose Delphi? Maybe it's because I'm not familiar with other development tools in depth, but the excellence of Delphi itself is at least one of the reasons! What's so great about Delphi? n The efficient development of Delphi is a RAD (Rapid application Development tool), which has a visual development environment. Of course, there are many development tools with similar functions (such as Visual Basic), but Delphi has the following unique features: 1 ) Delphi is truly object-oriented. All components in its VCL library built on OO technology can be inherited to create new components, including the form class TForm. In contrast, ActiveX components lack this flexibility. 2) Delphi's CodeInsight technology (i.e. code auto-completion function) is based on compiler information, while VB uses type library information. The advantage of using compiler information is more flexibility. However, programmers often complain that Delphi's code prompts take too long. In fact, I personally feel that after getting used to its speed, I can experience a sense of rhythmic pleasure. n The efficient Delphi language is based on the Object Pascal language. This is a truly object-oriented yet elegant language. It is not inferior to various other object-oriented languages in terms of functional integrity, but at the same time it is not greedy for more and blindly increases complexity. This allows developers to receive complete support when designing using various patterns without having to consider too many language/compiler details during implementation. n Compilation efficiency It can be said that Delphi is the fastest high-level language local code compiler on the Windows platform. What are the benefits of fast compilation? A fast compiler allows you to frequently switch between modifying code and compiling and running. At least, I am very accustomed to this way of working: run the program to see the effect, exit the program, modify a small amount of code, and then run the program. And Delphi's compiler never makes me feel waiting. n Efficient execution Delphi not only has fast compilation speed, but also the execution efficiency of the generated target code is very high. Delphi and C++Builder use the same back-end optimizer, so the code generated by it is as efficient as the code generated by an excellent C++ compiler. Delphi generates completely native code, so the executable file resulting from Delphi compilation can be executed and distributed independently (this is very important for the development of "green software"). No other runtime support is required. Of course, you can also choose dynamic link compilation, which can greatly reduce the length of the executable file. However, in this case, when distributing the program, the necessary runtime files must be distributed at the same time. n Efficient maintenance C++ gives a lot of decision-making power to programmers, so it is very powerful. However, at the same time, using C++ to write excellent object-oriented code requires programmers to have certain qualities. Delphi programmers will be limited to the framework provided by VCL to a certain extent (of course, you can get rid of VCL programming in Delphi). Relatively speaking, it is easier to create well-designed code. Visual Basic does not provide an object-oriented programming mechanism at all (VB6.0 and previous versions are based on objects, not object-oriented). The excellence of the code framework greatly reduces software maintenance costs. Based on all the above reasons, I choose Delphi!
1.3 Theme of this book
We usually write a lot of code, for the company, for ourselves or for friends. Sometimes, in order to verify an idea or learn a certain technology, I will write some experimental code. The life cycle of such code is very short and basically does not require maintenance. You can just write it as you like. However, when you really want to complete a project, code design is very important. Because such code requires long-term maintenance, constant modification or enhancement. Messy code design makes maintenance difficult or impossible, and modifying such code means more bugs or disaster. Therefore, before code can be written, it needs to be designed. The design mentioned here does not refer to functional design, but refers to the design of the code framework by programmers before coding, so that the code will be easier to understand and maintain in the future. I often hear a saying: A programmer's program life is only 35 years old. I never believe that a programmer's lifespan is only 35 years old. Maybe after the age of 35, the implementation ability (actually the craftsmanship ability) may decline, while the design ability does not decrease but increases with the increase of experience. This is the most precious thing. The backbone of foreign software development teams are generally people around 40 years old. Those are master programmers. The so-called programmers who cannot be programmers after the age of 35 are not qualified to be called programmers at all. Software engineering needs to turn programmers into coders and become a link in the assembly line, and the design work is completed by specialized designers (such as framework designers). Perhaps, the trend is to refine the division of labor, but whether we are satisfied with being coders or hope to grow into designers depends on our vision and efforts. Open up your horizons, rather than limiting yourself to and indulging in "achieving masters". Realization ability is the foundation. Only with certain realization ability can we grow. However, it is only a necessary condition, not a sufficient one. Otherwise, it would be like climbing to the mountainside and thinking that you have reached the top of the mountain and stagnating. Then, you can only be a coder, and your program life span is only 35 years old. After gaining this perspective, I hope this book can help you get started. Books related to Delphi published in China basically explain implementation. The title of this book is "Breakthrough by Delphi Masters". So, assume that you are now a Delphi master. Therefore, this book will not cover too many implementation techniques. Although there are example codes, the focus is on the design of its architecture, not its implementation. At this point, you may have guessed the theme of this book: how to use object-oriented technology in Delphi to build well-designed code. In my opinion, writing code is artistic creation. Elegant code is self-explanatory without the need for excessive comments. When there are too many comments, it is time to consider whether the design is reasonable. Writing a book should also be an artistic creation. If you can tell readers your own understanding and experience artistically without needing too many "annotations" (nonsense that wastes space), it will be very successful. I hope I can do it, at least try my best.
1.4 Summary
I believe that it is inevitable for me to embark on the path of programming. Being able to become a professional programmer is also what I dreamed of and realized. However, it should be said that the appearance of Delphi and the fact that I got to know, became familiar with it, became obsessed with it and became a part of my work was an unexpected surprise. What I want to say here is that you should be more insistent on yourself. When you have clearly positioned yourself and clearly know the path you have chosen, you no longer need to have any doubts or scruples and just keep going. Although I may not succeed in the end (of course, everyone’s definition of success is different), I love what I love without any regrets!