Re: [fpc-pascal]Class Identification?
On Monday 24 March 2003 00:31, you wrote: > > btw, all classes are implicit descendants of TObject. If you don't > > specify any base class, the class will be derived from TObject directly: > > > > type > > TMyClass = class > > procedure Something; > > ... > > end; > > > > TMyClass is automatically inherited from TObject > > > > Both postings sound like this wasn't clear... > > > > > > - Sebastian > > Indeed.. I did not know this. ^_^ Thank you very much. Nor did I - Thank you. I'd like to ask several questions: 1. What is then the difference between a class without ancestor, and a class inheriting from TObject? 2. Will TObject remain the "default ancestor" in the future? 3. Efficiency: Sometimes I use classes without ancestor, with the assumption, that this might be more efficient in cases where TObject's methods and fields are not necessary. It seems that assumption was wrong. To save resources, should I use explicite pointers to objects when I don't need the features inherited by the class TObject? Thanx, Anton. -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Class Identification?
On Mon, 2003-03-24 at 18:17, Anton Tichawa wrote: > Nor did I - Thank you. I'd like to ask several questions: > > 1. What is then the difference between a class without ancestor, and a class > inheriting from TObject? There is no difference > 2. Will TObject remain the "default ancestor" in the future? Yes > 3. Efficiency: Sometimes I use classes without ancestor, with the assumption, > that this might be more efficient in cases where TObject's methods and fields > are not necessary. It seems that assumption was wrong. To save resources, > should I use explicite pointers to objects when I don't need the features > inherited by the class TObject? No, I won't use classes in such cases. You could use objects (i.e. use the old object model introduced in Turbo Pascal 5.5, instead of Delphi's object model), they won't add any overhead. OTOH I don't recommend to use the old objects anymore, because almost all new high-level units use classes, and mixing classes with objects will lead to really ugly code. The methods of TObject don't add overhead. The memory usage is very low as well: Only a single pointer (VMT pointer), plus the data fields of your class. But the VMT data has to be stored in the executable, including some relocations. Constructing and destructing of TObject instances is somewhat slower that for the old objects, but I think you can neglect this in almost all cases. - Sebastian ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Class Identification?
To expand on Sebastians answer... > 2. Will TObject remain the "default ancestor" in the future? Yes, beacuse the Object Pascal that FPC supports is based on Borland Delphi's Object Pascal language (which is in part related to the Object Pascal standard created by the ISO or ANSI, I forget whuch one exactly.) Borland now have the defacto industrial standard Object Pascal implementation in the version of Object Pascal supported by Delphi. There are at least 3 compilers that support it, targetting multiple platforms (Delphi/Kylix, FPC, Virtual Pascal, and there a number of developers working on PDA versions of Object Pascal), on 10+ platforms. The only way it could change would be for Borland to lead the way. I believe even Delphi.NET is able to see the .NET 'Object' to be a 'TObject'. > 3. Efficiency: Sometimes I use classes without ancestor, with the assumption, > that this might be more efficient in cases where TObject's methods and fields > are not necessary. It seems that assumption was wrong. To save resources, > should I use explicite pointers to objects when I don't need the features > inherited by the class TObject? Write a procedure or function that takes a 'self' pointer to the data. This is basically what methods are at the end of the day. If you want better allocation performance, you can always refactor the memory allocation routines too. If FPC follows Delphi's model, there will be a record that holds the memort allocation routines. Have a look for the record type TMemoryManager that will probably be located in System or Sysinit unit. Altering the way these routines work can greatly improve speed and resource usage. One other point you really should use 'is' and not 'MyObject.ClassType'. Surely: if ( myinst is TButton ) then begin ... end; looks less ugly than: if ( myinst.ClassType = TButton ) then ... ; This is held up by the statement int he Borland help: > function ClassType: > > Description: ClassType dynamically determines the type of an object. It is > used internally by the is and as operators. > > Note: Applications should rarely, if ever, call ClassType directly. Instead, > use the is or as operator. Whether there is currently a good reason or it is just stylistic, I believe it's better to use the recognised syntax of a language rather than a convenient loophole. Just as TObject will stay with us forever now in it's current form, so will the 'is' and 'as' operators. Matt - This message was sent using Mistral WebMail. http://www.mistral.co.uk/ ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Class Identification?
On Mon, 24 Mar 2003 [EMAIL PROTECTED] wrote: > Write a procedure or function that takes a 'self' pointer to the data. This is > basically what methods are at the end of the day. > > If you want better allocation performance, you can always refactor the memory > allocation routines too. If FPC follows Delphi's model, there will be a record > that holds the memort allocation routines. Have a look for the record type > TMemoryManager that will probably be located in System or Sysinit unit. > Altering the way these routines work can greatly improve speed and resource > usage. > > One other point you really should use 'is' and not 'MyObject.ClassType'. > Surely: > > if ( myinst is TButton ) then begin >... > end; > > looks less ugly than: > > if ( myinst.ClassType = TButton ) then ... ; This is not entirely correct. The latter will return false for a descendent of TButton, while the former will give true. The exact statement corresponding to the 'is' operator is if myinst.Inheritsfrom(TButton) then ... ; Just crossing the t's and dotting the i's... Michael. ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal]OT: An FPC program in LinuxFormat Magazine
Just in case anybody needs some ammo against people who think pascal is dead. This months Linux format includes AJ's Internet Cafe For LTSP (now DireqCafe) which was written in FPC. Just goes to show, aint no proble it can't solve. And before anybody acuses me of just downright spamming, yes I am the A.J. that wrote it, and no I am not trying to make anybody buy it, it's GPL anyway. In case you do care, akinimod.sf.net, otherwize just ignore the post. A.J. -- "I'm a creationist. I refuse to believe that I could have evolved from man." A.J. Venter DireqLearn Linux Guru Public Key: http://www.mandrakesecure.net/en/cks/search.cgi?stype=keyid_4b&keyid_4b=F5AA10E9 ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]OT: An FPC program in LinuxFormat Magazine
A.J. Venter wrote: Just in case anybody needs some ammo against people who think pascal is dead. This months Linux format includes AJ's Internet Cafe For LTSP (now DireqCafe) which was written in FPC. Just goes to show, aint no proble it can't solve. And before anybody acuses me of just downright spamming, yes I am the A.J. that wrote it, and no I am not trying to make anybody buy it, it's GPL anyway. In case you do care, akinimod.sf.net, otherwize just ignore the post. A.J. I think such a posting isn't off topic and it's interessting to hear about such things :) ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Class Identification?
Michael, > This is not entirely correct. Neither is your explanation ;-) > The latter will return false for a descendent of TButton, while the > former will give true. The exact statement corresponding to the > 'is' operator is "The is and as operators use InheritsFrom in their implementations. The is operator, however, can only determine the inheritance relationship of an instance." So it would not be exactly the same in all instances. Besides, the original poster missed the point of inheritence and polymorphism by asuming that classtype was a good way to to run time type checking. Consider the following generic example: TTranslationType = (ttRaw, ttWav, ttMP3 ...); TTranslator = class function Translate(sin, sout: TStream): boolean; virtual; abstract; function getTranslatorType: TTranslationType; end; TWAVTranslator = class(TTranslator) function Translate(sin, sout: TStream): boolean; override; end; TMP3Translator = class(TTranslator) function Translate(sin, sout: TStream): boolean; override; end; TTranslatorClass = class of TTranslator; TTranslatorFactory = class ... procedure RegistreTranslator( newclass: TTranslatorClass ); function FindTranslator( translatorType: TTranslationType; translator: TTranslator): boolean; ... end; var Factory: TTranslatorFactory = nil; //constructed in the initialization ... var i, o: TFileStream; t: Translator; ... begin Factory.RegisterTranslator(TWAVTranslator); Factory.RegisterTranslator(TMP3Translator); ... if ( Factory.FindTranslator( ttMP3, t) ) then begin t.Translate( i, o ); ... end else raise Exception.Create('No Translator found'); ... end; .. You don't *need* to know the type of the class instance the factory returns, just that it supports the functionality you requested... Interfaces make this much nicer ;-) However, if you use the _is_ operator, the code will be a lot less complex if you did need to find the class type. The other thing worth noting is that the _is_ and _as_ operators work the same with Interfaces as they do with classes... THIS is why you should use them. > if myinst.Inheritsfrom(TButton) then ... ; The main difference is that it clearly stated in the D5 help that one should *not use* ClassType in the fashion indicated by the original poster. Matt - This message was sent using Mistral WebMail. http://www.mistral.co.uk/ ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]OT: An FPC program in LinuxFormat Magazine
On Mon, Mar 24, 2003 at 04:17:28PM +0100, Florian Klaempfl wrote: > A.J. Venter wrote: > >Just in case anybody needs some ammo against people who think pascal is > >dead. > >This months Linux format includes AJ's Internet Cafe For LTSP (now > >DireqCafe) which was written in FPC. > >Just goes to show, aint no proble it can't solve. > > > >And before anybody acuses me of just downright spamming, yes I am the > >A.J. that wrote it, and no I am not trying to make anybody buy it, it's > >GPL anyway. > >In case you do care, akinimod.sf.net, otherwize just ignore the post. > > > >A.J. > > I think such a posting isn't off topic and it's interessting to hear > about such things :) Absolutely. A lot of (up-them-selves) programmers tend to believe that pascal is a dead language, a language for kids. I'm happy to read of such a post. Just as a matter of interest, pascal might be an old language, a strongly typed language, but it is certainly NOT dead and any of my software engineer lecturers will agree with it's use as a language for developing software. my 2 cents... James > > ___ > fpc-pascal maillist - [EMAIL PROTECTED] > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]OT: An FPC program in LinuxFormat Magazine
On Monday 24 March 2003 23:16, you wrote: > On Mon, Mar 24, 2003 at 04:17:28PM +0100, Florian Klaempfl wrote: > > A.J. Venter wrote: > > >Just in case anybody needs some ammo against people who think pascal is > > >dead. > > >This months Linux format includes AJ's Internet Cafe For LTSP (now > > >DireqCafe) which was written in FPC. > > >Just goes to show, aint no proble it can't solve. > > > > > >And before anybody acuses me of just downright spamming, yes I am the > > >A.J. that wrote it, and no I am not trying to make anybody buy it, it's > > >GPL anyway. > > >In case you do care, akinimod.sf.net, otherwize just ignore the post. > > > > > >A.J. > > > > I think such a posting isn't off topic and it's interessting to hear > > about such things :) > > Absolutely. A lot of (up-them-selves) programmers tend to believe that > pascal is a dead language, a language for kids. I'm happy to read of > such a post. Just as a matter of interest, pascal might be an old > language, a strongly typed language, but it is certainly NOT dead and > any of my software engineer lecturers will agree with it's use as a > language for developing software. > > my 2 cents... > > James i aggree that pascal lives. i see it that way, as blaise pascal says, mathematically, there might be a real big chance, and if you multiply that real big chance with a probabilty of 50 %, you'll get surely more than one. that's a kind of carrefour (french; in english it's crossroad, i think) of mystery and calculus. pascal will live as long as some programmers bear in mind something like: *** begin repeat writeln('hello, world!'); if keypressed() then begin bla bla .. end; until false; end. *** because that might be of value in the future. that's a common feature of pascal and rock'n'roll, isn't it? anton. -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]OT: An FPC program in LinuxFormat Magazine
On Monday 24 March 2003 23:16, you wrote: > On Mon, Mar 24, 2003 at 04:17:28PM +0100, Florian Klaempfl wrote: > > A.J. Venter wrote: > > >Just in case anybody needs some ammo against people who think pascal is > > >dead. > > >This months Linux format includes AJ's Internet Cafe For LTSP (now > > >DireqCafe) which was written in FPC. > > >Just goes to show, aint no proble it can't solve. > > > > > >And before anybody acuses me of just downright spamming, yes I am the > > >A.J. that wrote it, and no I am not trying to make anybody buy it, it's > > >GPL anyway. > > >In case you do care, akinimod.sf.net, otherwize just ignore the post. > > > > > >A.J. > > > > I think such a posting isn't off topic and it's interessting to hear > > about such things :) > > Absolutely. A lot of (up-them-selves) programmers tend to believe that > pascal is a dead language, a language for kids. I'm happy to read of > such a post. Just as a matter of interest, pascal might be an old > language, a strongly typed language, but it is certainly NOT dead and > any of my software engineer lecturers will agree with it's use as a > language for developing software. > > my 2 cents... btw - please can you explain that idiom - "my 2 cents"? thanx. -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]OT: An FPC program in LinuxFormat Magazine
hello, list! On Monday 24 March 2003 23:16, you wrote: > On Mon, Mar 24, 2003 at 04:17:28PM +0100, Florian Klaempfl wrote: > > A.J. Venter wrote: > > >Just in case anybody needs some ammo against people who think pascal is > > >dead. > > >This months Linux format includes AJ's Internet Cafe For LTSP (now > > >DireqCafe) which was written in FPC. > > >Just goes to show, aint no proble it can't solve. > > > > > >And before anybody acuses me of just downright spamming, yes I am the > > >A.J. that wrote it, and no I am not trying to make anybody buy it, it's > > >GPL anyway. > > >In case you do care, akinimod.sf.net, otherwize just ignore the post. > > > > > >A.J. > > > > I think such a posting isn't off topic and it's interessting to hear > > about such things :) > > Absolutely. A lot of (up-them-selves) programmers tend to believe that > pascal is a dead language, a language for kids. I'm happy to read of > such a post. Just as a matter of interest, pascal might be an old > language, a strongly typed language, but it is certainly NOT dead and > any of my software engineer lecturers will agree with it's use as a > language for developing software. > > my 2 cents... > > James i aggree that pascal lives. i see it that way, as blaise pascal says, mathematically, there might be a real big chance, and if you multiply that real big chance with a probabilty of 50 %, you'll get surely more than one. that's a kind of carrefour (french; in english it's crossroad, i think) of mystery and calculus. pascal will live as long as some programmers bear in mind something like: *** begin repeat writeln('hello, world!'); if keypressed() then begin bla bla .. end; until false; end. *** because that might be of value in the future. that's a common feature of pascal and rock'n'roll, isn't it? anton. -- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). -- Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien mobil: +43 664 52 07 907 email: [EMAIL PROTECTED] -- ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal