NO.0 Title: Zhu Yuanqi: About Delphi erupted in a class called Problem of the parent class virtual functions: Shi Weigang Time: 2002-9-28 15:03:12 two Delphi class, the following statement: TFather = class public procedure ShowMe; Virtual; end; tson = class (tfather) public procedure showme; override; end; ----------------------- below is implementation {tfather} procedure tfather .Showme; Begin ShowMessage ('Hi, This Is Father!'); End; {Tson} Procedure Tson.Showme; Begin ShowMessage ('Hi, This Is Son'); End; ---------- ----------------------------- Now there is such a program: procedure foo; var am ASON: TSON; begin ason: = tson.create Try {How to call SHOWME in TFather through Ason? } finally ason.free; end; end; I want to know how to call the parent class TFather's SHOWME method in the above program section, and only convert the variable forced type to the parent class, but I am in Delphi. Tfather (Ason) .Showme, is displayed or "Hi, this is Son". Is there a high person telling me how to display "Hi, this is Father" through Ason?
[Follow this article] [Reply] [Reference] [Back] [Delete]
NO.1 Title: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang Time: 2002-9-28 15:08:31 this post we have a lot of palindromes, unfortunately It is the database that the database is broken.: (At that time, I think this implementation of C is the concept of virtual functions. Today I will try the class forced conversion and class virtual functions, discover both. The effect is exactly the same! #Include "stdafx.h" #include "iostream.h" Class CF {Virtual void showme () = 0;}; Class Ca: public cf {public: int U; void showme () {cout < <"A:" <<
U = 9; a = b; A-> showme (); return 0;} Run results: B: 9 confirmed yesterday my opinion: The dynamic binding function changed without as calling, it is constant for objects of.
[Reply] [Reference] [Back] [Delete]
NO.2 Title: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang time: 2002-9-2815: 10:41 // paste my article again, hoping To discuss with everyone, I don't think this is a language problem. The implementation of C is not OOP, and I think it is not very clear. OOP languages such as Java, Object Pascal, C #, etc. have objects, lists, etc. Object, they don't have to manage objects, as long as they are objects; if some algorithms are implemented, if you sort, I first define a abstract class Tcompaready = Class Function CompareObj: Integer; Virtual; Abstract; End; (Java is better, Delphi's interface is too close, very close, very dislike), then you can implement this class. I don't have to take a specific comparison, and I don't have to manage how they are specific. These are the old talks, everyone can be familiar. However, if the function called after the type conversion is the function of the base class, then these "older talks" cannot be implemented. I can only copy a set of algorithm functions for a specific class. Zhu Yuanqi's question is not a language problem, but a design problem. The virtual function is a declaration that declares that this class will have this function. The specific implementation is what you need to manage each particular class. Many times, the realization of the subclass is just the extension of the parent class, so Delphi provides a powerful inherited keyword, which adds a lot of convenience to the class design. At the same time, as seen now, it has caused a confusion to the class concept. I think that the virtual function needs a subclass to complete the implementation of your own, for an object, actually to call the implementation of the parent class, which can only be said to be an embodiment of a certain error in class design. A TSON object, converted to a parent class with an AS keyword or a direct mandatory type or a direct mandatory type (which is actually any class), the dynamic binding function address such as virtual functions is not changed, in short, The implementation of the father's class is not found. So I think Delphi can't achieve Zhu Yuanqi's wish. The following example is a simple description of this question: ta = class s: string; procedure showme; end; tb = class s: string; procedure showme; end; // Implement the following {tb} procedure tb.showme; begin showMessage ('TB : ' s); end; {ta} procedure ta.showme; begin showMessage (' ta: ' s); end; below is a code VAR A: Ta; B: Tb; Begin A: = Ta.create; as: = 'laugh'; b: = tb (a); b.Showme; a.free; end; what should you think? Is 'TB: Laugh'! Because Showme is not a dynamically binding function, no matter what the object is, what kind of implementation is used in what class call.
(As for the 'laugh', why can it be taken, so the memory structure of two classes is the same, if the TA definition is changed to Ta = Class I: Integer; s: string; procedure showme; end; then display 'TB:', Because the TB should be a string in memory now is zero integer, both empty strings) Classification definitions TF = Class Procedure Showme; Virtual; Abstract; End; TA = Class (TF) s: string; procedure SHOWME; OVERRIDE; END; TB = Class (TF) s: string; procedure showme; override; end; the same code, this display is 'Ta: laugh'! For dynamically binding functions, the address is not as calling class Change. At this time, TA is changed to Ta = Class (TF) i: integer; s: String; procedure showme; override; end; program display or 'ta: laugh'! Reason is. Note: The same is not changed, and it is said to be referred to the object. The virtual function is called dynamic binding in the documentation is to be referred to. (Because the class does not know where the implementation is in the end), I understand it very little, and it is my own knowledge. I have not referred to what authoritative work, but I usually use some experiences of the class, maybe many places. ^ _ ^ [Reply] [Reference] [Back] [Delete]
NO.3 Title: Re: Zhu Yuanqi: About Delphi erupted class virtual function call the parent class's a question of: Gou Qi Time: 2002-9-28 15:30:23 "I want to know how the comments section in the top block Calling the parent class TFather's SHOWME method, as long as the variable is converted into the parent class, "in C , it is not true, the correct is Tson * pson = new cson; pson-> showme ); // I'm Son; (tfather *) pson -> showme (); // I'm Son, Too; tfather * pfather = pson; pfather-> showme (); // I'm Son Another Time; Pson-> Tfather :: Showme (); // I'm father!
[Reply] [Reference] [Back] [Delete]
On a question about the class erupted in Delphi calls the parent class virtual functions:: NO.4 Title: Re: Re: Zhuyuan Qi Shi Weigang Time: 2002-9-28 15:32:36 strong! Hey, my C is too weak, I didn't expect to call it. Delphi seems to have no such function :(
[Reply] [Reference] [Back] [Delete]
NO.5 Title: Re: Re: Re: Zhu Yuanqi: About Delphi erupted class virtual function call the parent class's a question of: Gou Qi time: 2002-9-2815: 57: 50java in the realization of the concept of interfaces in C can be implemented in multiple inheritance abstract base classes. The IN java: class CFather interface IMother; class CSon public CFather implement IMother; IN c ; class CFather; class CMother {CMother (); virtual ~ CMother () = 0;} class CSon: public CFather, public CMother; as java Design The purpose is to create a simple, secure language than C , so remove the multiple inheritances, pointers in C , and add a mechanism for garbage disposal. This certainly throws the most powerful function of C . The processing of programmers pointers in the level is really a dream, but for the master of C , it is a wonderful realm. However, Java (also VB, Delphi) makes this world programmer more and more, and everyone can be programmed as a kind of entertainment, but very few people can enjoy it before, not everyone can design the system program. There is no container in C . Because C is a machine-oriented design, it has been highly abstract, but only provides the most basic functionality. The STL library in standard C is the perfect combination of algorithms and containers. There is no language that can be achieved with a language that can be compared to the library. Sort them? The latest JDK1.4 now provides Generic Collection Library to provide similar features. But the efficiency is far away, and I think this is conflict with Java's design thoughts, because the current Java is more and more complicated, and it is completely different from Java1.0. [Reply] [Reference] [Back] [Delete]
NO.6 Title: Re: Re: Re: Re: Zhu Yuanqi: About Delphi erupted class virtual function call the parent class's a question of: Zhu Yuanqi Time: 2002-9-28 17: 15: 57to Gou Qi: because of differences in language In fact, the variables in Delphi actually be equivalent to the pointer in C , I can see the post on the small white back (in the VC block) in C . To Schiwei: I carefully consider it. In the truth, you should talk about the design problem. However, in the beginning of the design, there is no way to completely consider it, but if you rely on refactoring, you will take a lot of energy, and if it is the class realized by others, you can't modify his design, what would you do? Therefore, Delphi did not provide the corresponding implementation mechanism I think it is a regret. Regarding the problem of the container you start, only the language that only provides template classes can be achieved, such as C . If Delphi also implements the container, it can only be implemented by a single structure or interface, but the type of fate is safe.
[Reply] [Reference] [Back] [Delete]
NO.7 Title: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang Time: 2002-9-28 17:22:50 think a programmer Articles specially discussing Code Refactoring articles, I think it is very emotion. Our company is now lacking is the time and human hand to do these things. It can be said that Refactoring is a very important proportion in the software development cycle. [Reply] [Reference] [Back] [Delete]
NO.8 Title: Re: Re: Re: Re: Re: Zhu Yuanqi: About Delphi erupted class virtual function call the parent class's a question of: Zhu Yuanqi Time: 2002-9-28 17:23:17 wrote a few interesting class, Tieshanglai Bo laugh: type TMan = class // mankind public procedure GotoWork; virtual; // work end; TSweetGun = class (TMan) private procedure EatBreakfast; // breakfast public procedure GotoWork; override; // end work Procedure Tsweetgun.gotoWork Begin Eatbreakfast; inherited; END; The above is a simple class declaration and implementation. The following function is to explain that if the Sweetgun's pot is broken, he has only don't have breakfast. Begin swg: = tsweetgun.create; if the pot didn't blew the swg.gotoWork; // Inside the time to eat breakfast process Else IF cooked THEN {here if it can provide a mandatory type conversion similar to C to call the parent method The mechanism is good, otherwise, you need to change the design of the TSWEETGun class. For example, in front of GotoWork, it is not a statement. Because the design, Sweetgun has not moved, all in the hotel, so don't consider the problem of the pot, but If you want to change your design, it will be designed to modify it. Is it a bit tired? End; In fact, I will know that Delphi can't be realized after DEPHI and VC, mainly put it on the discussion, huh, huh.
[Reply] [Reference] [Back] [Delete]
NO.9 Title: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Zhu Yuanqi Time: 2002-9-28 17:27:55 In fact, do Refactoring is involved in a development method, but also developers in designing and coding, further improvement, so I think the company should do these discussions, do some necessary training for everyone, so that the company's development Efficiency and quality are very beneficial.
[Reply] [Reference] [Back] [Delete]
NO.10 Title: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang Time: 2002-9-28 17:30:11 I think this There is a problem with TSWEETGun implementation. ^ _ ^ This kind of code is dangerous, TSWEETGUN is clearly a condition, relatively, it is absolute, but he is indeed unconditional in absolute time. I think TSweetGun be achieved: TSweetgun = Class (TMan) private procedure EatBreakfast; // breakfast public procedure GotoWork; override; // work end; to achieve the following procedure TSweetgun.GotoWork; begin if TimeEnough and PosibleToEat then EatBreakfast; inherited GotoWork; End; TimeEnough and POSIBLETOEAT can be a member function of TSWEETGUN, or a full-class function. Because the judgment of both is universal. [Reply] [Reference] [Back] [Delete]
NO.11 Title: Re: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Zhu Yuanqi Time: 2002-9-28 17:33:02 From Strictly speaking, it is dangerous, but here is omitted to other conditions in order to express the relationship between eating and later highly highlighted pots.
[Reply] [Reference] [Back] [Delete]
NO.12 Title: Re: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang Time: 2002-9-28 17:37:25 As After the implementation, the use of TSWEETGUN is not necessary to do what he has to do before working, he just speaks swg.gotoWork. Just like the company wants me to go to work at 9 o'clock, this is my interface, what personal needs before work, the company will not be involved, or it is inevitable. ^ _ ^ If you have written this, Tman is written like this, and I can't change this. I will do this TSWEETGUNEX = Class (TSWeeetgun) public procedure gotoWork; Override; END; implement the following Procedure Tsweetgunex .GotoWork; begin if TimeEnough and PosibleToeat dam; END; if the original PAS file does not make me change, TimeEnough, etc. a bit more. Oh, in fact, the principle is one: Subclass management is the implementation of virtual functions.
[Reply] [Reference] [Back] [Delete]
On a question about the class erupted in Delphi calls the parent class virtual functions:: NO.13 Title: Re: Re: Re: Re: Re: Re: Re: Re: Zhuyuan Qi Zhu Yuanqi Time: 2002-9-28 17:42: 36 Oh, inheriting a class is also possible, but you have to maintain a class that only to expand a function, if you brought too much maintenance in actual operation, it is estimated that the boss will be unhappy. - ^
[Reply] [Reference] [Back] [Delete]
NO.14 Title: Re: Re: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shao GMT: 2002-9-28 17:42 : 51 two boss, refactoring is what? [Reply] [Reference] [Back] [Delete]
NO.15 Title: Re: Re: Re: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang time: 2002-9-299: 06:16 can be translated into code reconstruction ^ _ ^
[Reply] [Reference] [Back] [Delete]
NO.16 Title: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Shi Weigang Time: 2002-9-29 9:36:26 "Programmer" 2001-12 Refactoring has a special discussion, recommend everyone to see // devserver / Wang Qifei library / comprehensive / magazine / "programmer" / 2001-12.pdf
[Reply] [Reference] [Back] [Delete]
NO.17 Title: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Zhu Yuanqi Time: 2002-9-29 9: 37: 32faint, white Replies to find, heavy Strap here (originally in the VC version) ---------------------------- #include "stdafx.h" #include
Class cfather {public: virtual void showme () {cout << "Hi, this is favor" <
SHOWME (); cfather (* pson) .showme (); // Mandatory type conversion delete pson; getChar (); return 0;}
[Reply] [Reference] [Back] [Delete]
NO.18 Title: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Zhu Yuanqi time: 2002-9 -29 9: 50: 55Refactoring mainly used in some agile development methods, such as XP, but the development personnel itself is relatively high. For these methods, I think it is quite high and cannot be promoted. Discussion on these issues, if you are interested, you can open a post to discuss it. To be honest, although and Sewang has opinion on the left place, you can deepen a lot of knowledge: P. In fact, everyone's point of view is not contradictory. Swivang mainly emphasizes the perfect design and active defense against Delphi, and I mainly emphasize that Under the premise of not change the design (so that there is no development cycle), I hope that Delphi can provide a flexibility similar to C . Change, because there is no, so you can only regret. I hope that everyone can make more discussions to these aspects, with a view to improve.
[Reply] [Reference] [Back] [Delete]
NO.19 Title: Re: Re: Re: Zhu Yuanqi: About Delphi erupted in a class called Problem of the parent class virtual functions: Gou Qi Time: 2002-9-29 9:51:11 "CFather (* pSon) .ShowMe (); // Mandatory Type Conversion 'This is not forced type conversion. Instead, a CFather object is created. For the VC compiler, it provides two constructor defaults, one is without parameters, one is CFather (Cfather & ), The second function does not do, just copy all the memory data of the source object, so this is independent of the virtual function. If you open the VC debugger will find PSON's address and cfather (* pson) The pointer is not the same [Reply] [Reference] [Back] [Delete]
NO.20 Title: Re: Re: Re: Re: Zhu Yuanqi: About Delphi erupted class virtual function call the parent class's a question of: Zhu Yuanqi Time: 2002-9-29 9:59:31 specially engaged in C is Niua :). From implementation, it is new to construct an object, but in my impression, since the written method of the basic type of forced type conversion is the same, I want to call the mandatory type conversion. Oh, changed a mistake. : P
[Reply] [Reference] [Back] [Delete]
NO.21 Title: Re: Re: Re: Re: Re: Zhu Yuanqi: a question of class erupted about Delphi calls the parent class virtual functions: Wang Wei Time: 2002-9-29 10:18:04 Oh, the original with delphi The mandatory conversion is still the point of view of the gap. It is indeed a cattle.
[Reply] [Reference] [Back] [Delete]