[fpc-pascal]init a class from another class
memsom at interalpha.co.uk
Tue Oct 9 22:47:14 CEST 2001
Taking on board what Jonas has said (you have mixed Turbo Pascal syntax with
that of Object Pascal/Delphi)..
>tCoDec = CLASS
> constructor Create; VIRTUAL;
> destructor Destroy; override;
>tmyCoDec = CLASS (tCoDec)
> constructor create; OVERRIDE;
> destructor Destroy; OVERRIDE;
>pCodecList = ^tCodecList;
>tCodecList = RECORD
> codec :tCoDec;
> next :pCodecList;
Does FPC have a TList? Surely that would work out better.
>tMain = CLASS
> codec_list :pCodecList;
> constructor create;
> destructor destroy; override
> registerCoDec (cd :tCoDec); //doesn't need 'var', all classes are passed
> //cd := "class of cd".init; why do you need this line??
because tMyCoDec inherits from tCoDec, you may pass it as a tCoDec. You will
then need to typecast it to get at any 'added' features, but this is normal
even in languages such as C/C++.
>I don't know how to do this or if it's possible. It's the first time I use
>classes and maybe the first I use OOP at all, so maybe this is completely
>impossible to do.
Nope, I do this all the time. I have just written a fairly complex
administration tool that uses small data classes to pass information around
in a similar wat to above. In all cases the routine that accepts the data
uses the base class as the param, so that I can typecast where needed, but
simplify the overall routines.
Don't have BeOS? Get it! - http://free.be.com/
Wanna keep BeOS alive? Save BeOS -
-----BEGIN GEEK CODE BLOCK-----
GCS d? s+++:+ a- C++ UL+ P L++ E---- W- N+ o+ K- w
O- M V PS PE-- Y PGP- t- 5-- X- R- tv+ b+ DI++ D+
G e++ h--- r+++ y+++
------END GEEK CODE BLOCK------
More information about the fpc-pascal