Classes with abstract methods

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Classes with abstract methods

Damien Gerard

With fpc you can get "myfile.pas(77,47) Warning: Constructing a class  
"xxxx" with abstract methods"
I just would like to know why it is allowed to build classes with  
abstract methods. AFIK it is different from other compilers and it is  
a bit strange for me.


--
Damien Gerard
[hidden email]

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Michael Van Canneyt


On Mon, 14 Jan 2008, Damien Gerard wrote:

>
> With fpc you can get "myfile.pas(77,47) Warning: Constructing a class "xxxx"
> with abstract methods"
> I just would like to know why it is allowed to build classes with abstract
> methods. AFIK it is different from other compilers and it is a bit strange for
> me.

Delphi gives exactly the same warning.

It is allowed to create such instances: as long as you don't call any of the
abstract methods, there will be no problem.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Damien Gerard

On Jan 14, 2008, at 10:27 AM, Michael Van Canneyt wrote:

>
>
> On Mon, 14 Jan 2008, Damien Gerard wrote:
>
>>
>> With fpc you can get "myfile.pas(77,47) Warning: Constructing a  
>> class "xxxx"
>> with abstract methods"
>> I just would like to know why it is allowed to build classes with  
>> abstract
>> methods. AFIK it is different from other compilers and it is a bit  
>> strange for
>> me.
>
> Delphi gives exactly the same warning.

I don't remember that.

> It is allowed to create such instances: as long as you don't call  
> any of the
> abstract methods, there will be no problem.


Is there a way to abort the compilation in this cases instead of a  
warning ?


--
Damien Gerard
[hidden email]

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Michael Van Canneyt


On Mon, 14 Jan 2008, Damien Gerard wrote:

>
> On Jan 14, 2008, at 10:27 AM, Michael Van Canneyt wrote:
>
> >
> >
> >On Mon, 14 Jan 2008, Damien Gerard wrote:
> >
> > >
> > >With fpc you can get "myfile.pas(77,47) Warning: Constructing a class
> > >"xxxx"
> > >with abstract methods"
> > >I just would like to know why it is allowed to build classes with abstract
> > >methods. AFIK it is different from other compilers and it is a bit strange
> > >for
> > >me.
> >
> >Delphi gives exactly the same warning.
>
> I don't remember that.

D:\Temp>dcc32 unit1
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Clear'
Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Delete'
Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Insert'
Unit1.pas(32) Hint: Value assigned to 'T' never used
Unit1.pas(36)
37 lines, 0.11 seconds, 475 bytes code, 8 bytes data.

>
> >It is allowed to create such instances: as long as you don't call any of the
> >abstract methods, there will be no problem.
>
>
> Is there a way to abort the compilation in this cases instead of a warning ?

Currently not.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Graeme Geldenhuys-2
On 14/01/2008, Michael Van Canneyt <[hidden email]> wrote:
> >
> > Is there a way to abort the compilation in this cases instead of a warning ?
>
> Currently not.

If you want to be that strict, then use Interfaces instead of Abstract classes.


-
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Damien Gerard
In reply to this post by Michael Van Canneyt

On Jan 14, 2008, at 10:53 AM, Michael Van Canneyt wrote:

>
>
> On Mon, 14 Jan 2008, Damien Gerard wrote:
>
>>
>> On Jan 14, 2008, at 10:27 AM, Michael Van Canneyt wrote:
>>
>>>
>>>
>>> On Mon, 14 Jan 2008, Damien Gerard wrote:
>>>
>>>>
>>>> With fpc you can get "myfile.pas(77,47) Warning: Constructing a  
>>>> class
>>>> "xxxx"
>>>> with abstract methods"
>>>> I just would like to know why it is allowed to build classes with  
>>>> abstract
>>>> methods. AFIK it is different from other compilers and it is a  
>>>> bit strange
>>>> for
>>>> me.
>>>
>>> Delphi gives exactly the same warning.
>>
>> I don't remember that.
>
> D:\Temp>dcc32 unit1
> Borland Delphi Version 15.0
> Copyright (c) 1983,2002 Borland Software Corporation
> Unit1.pas(32) Warning: Constructing instance of 'TStrings'  
> containing abstract method 'TStrings.Clear'
> Unit1.pas(32) Warning: Constructing instance of 'TStrings'  
> containing abstract method 'TStrings.Delete'
> Unit1.pas(32) Warning: Constructing instance of 'TStrings'  
> containing abstract method 'TStrings.Insert'
> Unit1.pas(32) Hint: Value assigned to 'T' never used
> Unit1.pas(36)
> 37 lines, 0.11 seconds, 475 bytes code, 8 bytes data.
>

Yes I trust you don't wory, just my mind is playing with me :)

>>
>>> It is allowed to create such instances: as long as you don't call  
>>> any of the
>>> abstract methods, there will be no problem.
>>
>>
>> Is there a way to abort the compilation in this cases instead of a  
>> warning ?
>
> Currently not.

Thanks



--
Damien Gerard
[hidden email]

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Damien Gerard
In reply to this post by Graeme Geldenhuys-2

On Jan 14, 2008, at 11:00 AM, Graeme Geldenhuys wrote:

> On 14/01/2008, Michael Van Canneyt <[hidden email]> wrote:
>>>
>>> Is there a way to abort the compilation in this cases instead of a  
>>> warning ?
>>
>> Currently not.
>
> If you want to be that strict, then use Interfaces instead of  
> Abstract classes.


Indeed I should do this. Thanks



--
Damien Gerard
[hidden email]

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Matt Emson
In reply to this post by Graeme Geldenhuys-2
Graeme Geldenhuys wrote:
> On 14/01/2008, Michael Van Canneyt <[hidden email]> wrote:
>  
>>> Is there a way to abort the compilation in this cases instead of a warning ?
>>>      
>> Currently not.
>>    
>
> If you want to be that strict, then use Interfaces instead of Abstract classes

I always found (and still do in C#) that interfaces are good for forcing
structure but bad for forcing good inheritance trees. The good thing
about classes with abstract methods is that they form a point for
inheritance. Interfaces - well, I regularly use interfaces to create a
common structure, e.g. an API that will have both a webservice interface
and a local interface. The common API is an interface in a separate
assembly, used on both client and server to implement an identical API
(client code can then link to either the local API or the webservice via
a client that implements the same interface.) DotNet also makes
reflection (RTTI) quite useful with interfaces too, but I digress. The
point is that the webservice class, the client and the local API that
the webservice wraps all implement the interface (the webservice usually
just delegates responsibility to an internal instance), but none of them
inherit from each other.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Peter Vreman
In reply to this post by Damien Gerard
>> >It is allowed to create such instances: as long as you don't call any of the
>> >abstract methods, there will be no problem.
>>
>>
>> Is there a way to abort the compilation in this cases instead of a warning ?
>
> Currently not.

You can abort compilation in case of any warning with the -Sew option. The same goes for note or
hint with -Sen or -Seh, but those are only usefull for compiler tests.

Peter


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Michael Van Canneyt


On Mon, 14 Jan 2008, Peter Vreman wrote:

> >> >It is allowed to create such instances: as long as you don't call any of the
> >> >abstract methods, there will be no problem.
> >>
> >>
> >> Is there a way to abort the compilation in this cases instead of a warning ?
> >
> > Currently not.
>
> You can abort compilation in case of any warning with the -Sew option. The same goes for note or
> hint with -Sen or -Seh, but those are only usefull for compiler tests.

The problem with this mechanism is that if you have another warning which occurs first,
that will stop your compilation, you'll never get to the abstract warning...

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Damien Gerard

On Jan 14, 2008, at 11:55 AM, Michael Van Canneyt wrote:

>
>
> On Mon, 14 Jan 2008, Peter Vreman wrote:
>
>>>>> It is allowed to create such instances: as long as you don't  
>>>>> call any of the
>>>>> abstract methods, there will be no problem.
>>>>
>>>>
>>>> Is there a way to abort the compilation in this cases instead of  
>>>> a warning ?
>>>
>>> Currently not.
>>
>> You can abort compilation in case of any warning with the -Sew  
>> option. The same goes for note or
>> hint with -Sen or -Seh, but those are only usefull for compiler  
>> tests.
>
> The problem with this mechanism is that if you have another warning  
> which occurs first,
> that will stop your compilation, you'll never get to the abstract  
> warning...


I agree.
May be a new option in a future release of fpc ? :)
It would be nice to have a switch to do it.



--
Damien Gerard
[hidden email]

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Jonas Maebe-2

On 14 Jan 2008, at 14:43, Damien Gerard wrote:

> On Jan 14, 2008, at 11:55 AM, Michael Van Canneyt wrote:
>
>> The problem with this mechanism is that if you have another  
>> warning which occurs first,
>> that will stop your compilation, you'll never get to the abstract  
>> warning...
>
> I agree.
> May be a new option in a future release of fpc ? :)
> It would be nice to have a switch to do it.

There is already a feature request for the ability to turn off/on  
certain warnings in Mantis. Upgrading certain warnings (and hints/
notes) to errors is quite related. It should be quite doable for an  
outsider to implement this sort functionality, but until now no one  
has volunteered yet.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Damien Gerard

On Jan 14, 2008, at 2:59 PM, Jonas Maebe wrote:

>
> On 14 Jan 2008, at 14:43, Damien Gerard wrote:
>
>> On Jan 14, 2008, at 11:55 AM, Michael Van Canneyt wrote:
>>
>>> The problem with this mechanism is that if you have another  
>>> warning which occurs first,
>>> that will stop your compilation, you'll never get to the abstract  
>>> warning...
>>
>> I agree.
>> May be a new option in a future release of fpc ? :)
>> It would be nice to have a switch to do it.
>
> There is already a feature request for the ability to turn off/on  
> certain warnings in Mantis. Upgrading certain warnings (and hints/
> notes) to errors is quite related. It should be quite doable for an  
> outsider to implement this sort functionality, but until now no one  
> has volunteered yet.


I see. I will see what I can do next month.


--
Damien Gerard
[hidden email]

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Peter Vreman
In reply to this post by Damien Gerard
>>> The problem with this mechanism is that if you have another
>>> warning which occurs first,
>>> that will stop your compilation, you'll never get to the abstract
>>> warning...
>>
>> I agree.
>> May be a new option in a future release of fpc ? :)
>> It would be nice to have a switch to do it.
>
> There is already a feature request for the ability to turn off/on
> certain warnings in Mantis. Upgrading certain warnings (and hints/
> notes) to errors is quite related. It should be quite doable for an
> outsider to implement this sort functionality, but until now no one
> has volunteered yet.

Upgrade a warning to error can already be done by editing (replace a W with an E) the errore.msg
yourself and pass the modified errore.msg to the compiler with -Fr.

Peter


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Classes with abstract methods

Jonas Maebe-2

On 14 Jan 2008, at 15:45, Peter Vreman wrote:

>> There is already a feature request for the ability to turn off/on
>> certain warnings in Mantis. Upgrading certain warnings (and hints/
>> notes) to errors is quite related. It should be quite doable for an
>> outsider to implement this sort functionality, but until now no one
>> has volunteered yet.
>
> Upgrade a warning to error can already be done by editing (replace  
> a W with an E) the errore.msg
> yourself and pass the modified errore.msg to the compiler with -Fr.

You can similarly downgrade a warning to a note or hint by changing  
the W with a N or H, but the problem is that you have to redo this  
for each release.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal