Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-02

May I Interject? A Generic Inheriting a Generic in a Generic Way

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Raheman Velji

I have an idea called Interjections. I have posted on the forum so that everybody can access it nicely. Here are the links:

http://forum.lazarus.freepascal.org/index.php/topic,27452.0.html and its continuation
http://forum.lazarus.freepascal.org/index.php/topic,27453.0.html

Please include interjections in future versions of Free Pascal! And ask me questions and comments if you have any!

And many thanks to all you who make Free Pascal free!

Happy coding!
Raheman Velji

Reply by email

Sven Barth
to Raheman Velji
Raheman Velji wrote 9 lines
I have an idea called Interjections. I have posted on the forum so that everybody can access it nicely. Here are the links: http://forum.lazarus.freepascal.org/index.php/topic,27452.0.html and its continuation http://forum.lazarus.freepascal.org/index.php/topic,27453.0.html Please include interjections in future versions of Free Pascal! And ask me questions and comments if you have any!

You consider this "more readable"? Honestly, no... Code gets already convoluted enough if it uses macros, so something like that is definitely not needed. We are not C after all...

Also what you mentioned in your second article already works since quite some months in 2.7.1 and thus by extension in 3.0.0 and 3.1.1:

=== code begin ===

program tgeninherit;
{$mode objfpc}
type
   generic TMyListBase<data_type> = class
     procedure VirtualProc( data : data_type ); virtual; abstract;
     procedure InternalProc; // <-- which uses VirtualProc
   end;
   generic TMyList<data_type> = class(specialize TMyListBase<data_type>)
   end;
   TIntegerList = class(specialize TMyList<Integer>)
     procedure VirtualProc(data: Integer); override;
   end;
   TStringList = class(specialize TMyList<String>)
     procedure VirtualProc(data: String); override;
   end;
   TBooleanList = class(specialize TMyList<Boolean>)
     procedure VirtualProc(data: Boolean); override;
   end;
procedure TMyListBase.InternalProc;
begin
   VirtualProc(Default(data_type));
end;
procedure TIntegerList.VirtualProc(data: Integer);
begin
   Writeln(data);
end;
procedure TStringList.VirtualProc(data: String);
begin
   Writeln(data);
end;
procedure TBooleanList.VirtualProc(data: Boolean);
begin
   Writeln(data);
end;
begin
end.

=== code end ===

Regards,
Sven

Reply by email