Delphi

zhaozj2021-02-08  176

First, the old growth talks Delphi vs vc is already an old topic, but I still want to talk about it here, all the words, if I don't agree, please smile. The benefits of RAD are very easy to see, and the interface design is high by Delphi. I want to write an unconventional transparent button, delphi as long as I find a control, click the mouse, modify the caption is OK, VC? At least to write 10 lines of code to get it, of course, MFC's approach makes people understand the principle of Windows underlying, but the encapsulation of OOP is not very good. Developers should understand all the underlying to write code, for me The entry is a torture, because there is no need, it is now always nervous, the time is never enough, we can't expect the programmer to know all the aspects of Windows programming, some people understand the video, someone is very good to the network, but no one It is all talents, and the sample is unrealistic, so the package is very important. If I have to spend 30% or even more time in a transparent button or a beautiful interface, then I will go to the river:) Delphi is indeed better than MFC on the interface! Of course, it is not that MFC doesn't design a beautiful interface, just spending too long, not worth it. Rad is really good? Nor. At least for beginners is not because it is misunderstanding just moving the mouse, the pull frame, the final result is to make people feel that Delphi is used to write the interface, the bottom level can not do. It seems that the MFC programmer is this Delphi programmer: "What can your program be beautiful, what else can you do?" Wrong! In fact, in addition to DDK, what can't be developed? What is the header file Delphi of the API? Borland did not convert, JEDI was converted, even if jedi did not turn, the same thing did it, as long as I gave me C's header file, I can convert it, Jedi's short conversion instructions should be every Delphi programmer Essential documentation. The header file is converted, the rest is to write, MFC can do, Delphi can also! video? The internet? DirectX? Audio? Which Delphi can't do?

Second, the child process writes an event, many people are directly opened, no matter how long the code is, what is doing, as long as it is done in an event, an ancient brain writes, the result is a few months later re-revised At the time, there is no way because the code segment is too long. So why not open the code segment? People have limited attention, more than 100 lines of code look down, Delphi's seniors tell me one thing: all the process (here the process includes procedure and function) do not exceed 25 lines! Because this length of the code doesn't make you dizziness, you will easily understand what this process should do. So how do you open the thing that originally doing something? There are many ways, my experience is modular. For example, there are many different things in an event, then different things are different from different sub-processes, then call in the main process, most of the main process is some judgments and loops, and there will be no specific implementation process. This will give you a lot of code segments, but you will make your attention! Principle: A process only does one thing, and do it. Reference: The source code of VCL. Take a look at the source code of the VCL, very few code segments of more than 25 lines! Third, the parameter name remember that when I first learned SDK, I saw that Hungary said that there was too much! Can't remember! So I hate the inventor :) Finally Delphi appeared, wearing a day of dancing! In Delphi, it is a ridiculous and unnecessary variable name that defines a string with strdosomeset. As long as your process is short, there is no need for a prefix without global variables. For example: procedure SubPro; var i: byte; Width, Height: integer; begin Width: = GetWidth; Height: = GetHeight; for i: = 0 to 9 do begin DrawThread: = TDrawThread.Create; DrawThread.Width: = Width; Drawthread.height: = Height; DrawThread.start; end; end; I think there is no comment, it is easy to know what he has to do. So, please remove all prefixes and underscores, Delphi's programs don't need these! Our parameter name is as long as the verb noun, as long as the role of this parameter can, we don't want, simple is beautiful, Pascal is that the code is talking, not reading the heavens, your head is What do you think, the code is what is like. Beautiful, simple, this is the benefits of Pascal, please obey! Principle: Simple is beautiful!

Fourth, the child window is in the call of the sub-window, such as if setAlarmparamdlg.showmodal = mrok dam, alarmtimes: = start (setAlarmparamdlg.edit1.text); alarmarea: = setAlarmdlg. Spinedit1.Value; End; Day, if the user thinks that you use the Edit or Spinedit to be ugly, change a beautiful control, what do you do? Not only need to modify the code of the child window, but also modify the code of the main form. The procedure of one or two sub-windows will certainly not let you suffer, if is a program with more than 20 sub-forms? The reason for a day is just because it changed a control! Why not change a method? Representing the parameters you want to use, you will write less code. // main form if SetAlarmParamDlg.ShowModal = MrOK then begin AlarmTimes: = SetAlarmParamDlg.AlarmTimes; AlarmArea: = SetAlarmParamDlg.AlarmArea; end; // subform interfaceprivate FAlarmTimes: integer; FAlarmArea: integer; published property AlarmTimes: integer read FAlarmTimes Write FalarmTimes; Property Alarmarea: Integer Read Falarmarea Write Falarmarea;

Implementation ... FalarmTimes: = strt1.text); Falarmarea: = Spinedit1.Value; ModalResult: = Mrok; ...

As long as you stick to this, you will find the benefits, a child window only do his own things, the main window and his interaction are made through the attribute, as long as the interface is constant, the modification of the sub-window will not affect the main window. The code, no matter how the sample is changed, the control is replaced, how to modify the code, the entire program is still old, just the interface change. Principle: Modular Your sub-window, window is also a class, how to communicate between classes, how to communicate between windows

My text is not very good, not very good at expression, if there is any place to write, welcome to throw bricks :)

转载请注明原文地址:https://www.9cbs.com/read-3230.html

New Post(0)