home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6654 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.9 KB  |  51 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!utcsri!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: BP/TP OOP is missing something...
  5. Message-ID: <dmurdoch.282.722020256@mast.queensu.ca>
  6. Lines: 39
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <KIM.92Nov16125141@kim.Software.Mitel.COM> <1992Nov17.153804.21729@news.clarkson.edu>
  10. Date: Tue, 17 Nov 1992 17:10:56 GMT
  11.  
  12. In article <1992Nov17.153804.21729@news.clarkson.edu> kooijman@sun.soe.clarkson.edu (Harry Kooijman,Peyt314a,3808) writes:
  13. >Why is it that TP with objects does not have the capability to call the
  14. >constructors when variables are declared? And when an object goes out of
  15. >scope it should be destructed automatically. For example:
  16. >
  17. >Function DoSomethingWithD;
  18. >Var D:DoubleObject(1.2);
  19. >Begin
  20. >  ... 
  21. >  Do something with D
  22. >  ...
  23. >End; {and here D gets destructed}
  24.  
  25. This is there in TP, to a very limited extent:  you can have an initialized 
  26. variable which is an object, and you needn't call the constructor.  It's 
  27. initialized at program load time, not each time the variable comes into 
  28. scope.  The destructor is never called.
  29.  
  30. I think the main reason that TP doesn't have automatic constructor/
  31. destructor calls is because it is descended from Pascal.  In Pascal in 
  32. general, code doesn't get executed unless you explicitly ask for it.  
  33. Adding automatic code would be a big change to the flavour of the language.
  34.  
  35. It's pretty unlikely that Borland would make such a fundamental change
  36. that doesn't add any power to the language.  Your code fragment is exactly 
  37. equivalent to
  38.  
  39.  var D:DoubleObject;
  40.  begin
  41.    D.init(1.2);
  42.    ...
  43.    D.done;
  44.  end;
  45.  
  46. Since what you want to do is already possible with nothing more than a 
  47. couple of extra lines of code, why make a big change to the language?
  48.  
  49. Duncan Murdoch
  50. dmurdoch@mast.queensu.ca
  51.