Sign in Join

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

Mailing lists / lazarus / 2013-08

Forward declaration not solved

19 messages · 7 people ·

Reply by email Subscribe to this list Your subscription

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

Antonio Fortuny

Hi Folks.

Moving some units from Delphi to FPC-Lazarus, the FPC compiler tells me something I do not understand:
Platform is Linux_x64, Lazarus 1.0.8 FPC 2.6.2, gtk2 Project options have been set to Obj Pascal (mdelphi removed)

interface
     uses ...
[324]    function OpenLongFileName(const ALongFileName: String; const
SharingMode: Integer): THandle;
implementation
uses ...
function OpenLongFileName(const ALongFileName: String; const
SharingMode: Integer): THandle;
begin
   if not FileExists(ALongFileName) then begin
     with TStringList.Create do try
       Clear;
       SaveToFile(ALongFileName);
     finally
       Free
     end;
   end;
   Result := FileCreate(ALongFileName, fmOpenReadWrite, SharingMode);
end;

compiler says:

clamav3.pas(324,12) Error: Forward declaration not solved
"OpenLongFileName(const AnsiString,const LongInt):QWord;"

Any comment ?

Thanks,

Antonio.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/25feed26/attachment.html>

Reply by email

Mattias Gaertner
to Antonio Fortuny
Show quoted text 37 lines
Hi Folks. Moving some units from Delphi to FPC-Lazarus, the FPC compiler tells me something I do not understand: Platform is Linux_x64, Lazarus 1.0.8 FPC 2.6.2, gtk2 Project options have been set to Obj Pascal (mdelphi removed) interface uses ... [324] function OpenLongFileName(const ALongFileName: String; const SharingMode: Integer): THandle; implementation uses ... function OpenLongFileName(const ALongFileName: String; const SharingMode: Integer): THandle; begin if not FileExists(ALongFileName) then begin with TStringList.Create do try Clear; SaveToFile(ALongFileName); finally Free end; end; Result := FileCreate(ALongFileName, fmOpenReadWrite, SharingMode); end; compiler says: clamav3.pas(324,12) Error: Forward declaration not solved "OpenLongFileName(const AnsiString,const LongInt):QWord;" Any comment ?

Maybe there is a unit in your implementation uses section that redefines THandle.

Mattias

Reply by email

Antonio Fortuny
to Mattias Gaertner

Le 09/08/2013 10:22, Mattias Gaertner a ?crit :

Show quoted text 6 lines
clamav3.pas(324,12) Error: Forward declaration not solved "OpenLongFileName(const AnsiString,const LongInt):QWord;" Any comment ? Maybe there is a unit in your implementation uses section that redefines THandle.

On the declaration (following Ctrl + mouse left click) leads to QWord: THandle --> PtrUInt (LCLType) --> QWord (systemh.inc) on the implementaion: THnadle --> System.THandle (sysutilf.inc) --> THandle --> LongInt (sysosh.inc)

Well done. In the interface units uses declares:   LCLIntf, LCLType,
LMessages,  FileUtil;
In the implemantaion uses declares   Classes,  sysutils;
OK. It is a Delphi conversion and I didn't pay enough attention to it

But the isn't there some ambiguity between LCL declarations and FPC declarations for what is obviously the same type ? Thanks Mattias,

Antonio.

Show quoted text 9 lines
Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Sven Barth
to Antonio Fortuny
Antonio Fortuny wrote 20 lines
Le 09/08/2013 10:22, Mattias Gaertner a ?crit : > clamav3.pas(324,12) Error: Forward declaration not solved > "OpenLongFileName(const AnsiString,const LongInt):QWord;" > > Any comment ? > Maybe there is a unit in your implementation uses section that > redefines THandle. On the declaration (following Ctrl + mouse left click) leads to QWord: THandle --> PtrUInt (LCLType) --> QWord (systemh.inc) on the implementaion: THnadle --> System.THandle (sysutilf.inc) --> THandle --> LongInt (sysosh.inc) Well done. In the interface units uses declares: LCLIntf, LCLType, LMessages, FileUtil; In the implemantaion uses declares Classes, sysutils; OK. It is a Delphi conversion and I didn't pay enough attention to it But the isn't there some ambiguity between LCL declarations and FPC declarations for what is obviously the same type ?

Might be related to the fact that the LCL often uses the THandle to store a pointer on non-Windows widgetsets. On e.g. Linux x86_64 THandle is defined as a longint because of file operations... There might not be a solution with which anyone can live :/

Regards,
Sven

Reply by email

Antonio Fortuny
to Sven Barth

Le 09/08/2013 11:29, Sven Barth a ?crit :

Show quoted text 25 lines
Am 09.08.2013 11:15, schrieb Antonio Fortuny: > > Le 09/08/2013 10:22, Mattias Gaertner a ?crit : >> clamav3.pas(324,12) Error: Forward declaration not solved >> "OpenLongFileName(const AnsiString,const LongInt):QWord;" >> >> Any comment ? >> Maybe there is a unit in your implementation uses section that >> redefines THandle. > On the declaration (following Ctrl + mouse left click) leads to > QWord: THandle --> PtrUInt (LCLType) --> QWord (systemh.inc) > on the implementaion: THnadle --> System.THandle (sysutilf.inc) --> > THandle --> LongInt (sysosh.inc) > > Well done. In the interface units uses declares: LCLIntf, LCLType, > LMessages, FileUtil; > In the implemantaion uses declares Classes, sysutils; > OK. It is a Delphi conversion and I didn't pay enough attention to it > > But the isn't there some ambiguity between LCL declarations and FPC > declarations for what is obviously the same type ? Might be related to the fact that the LCL often uses the THandle to store a pointer on non-Windows widgetsets. On e.g. Linux x86_64 THandle is defined as a longint because of file operations... There might not be a solution with which anyone can live :/

OK, I think I can live with this. But I think it would be preferable to use a distinct type name. As I can understand that the system unit is quite close to the OS definitions it should not be superseded by Lazarus. Anyway, thanks for the explantion Sven.

Antonio.

Show quoted text 9 lines
Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/defbb635/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: ebedgiig.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/defbb635/attachment.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: dcbfccig.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/defbb635/attachment-0001.jpg>

Reply by email

Mattias Gaertner
to Antonio Fortuny: Le 09/08/2013 10:22, Mattias Gaertner a ?crit : On the declaration (following Ctrl +…
Show quoted text 24 lines
Antonio Fortuny hat am 9. August 2013 um 11:15 geschrieben: [...] Le 09/08/2013 10:22, Mattias Gaertner a ?crit : > clamav3.pas(324,12) Error: Forward declaration not solved > "OpenLongFileName(const AnsiString,const LongInt):QWord;" > > Any comment ? > Maybe there is a unit in your implementation uses section that > redefines THandle. On the declaration (following Ctrl + mouse left click) leads to QWord: THandle --> PtrUInt (LCLType) --> QWord (systemh.inc) on the implementaion: THnadle --> System.THandle (sysutilf.inc) --> THandle --> LongInt (sysosh.inc) Well done. In the interface units uses declares: LCLIntf, LCLType, LMessages, FileUtil; In the implemantaion uses declares Classes, sysutils; OK. It is a Delphi conversion and I didn't pay enough attention to it But the isn't there some ambiguity between LCL declarations and FPC declarations for what is obviously the same type ?

The problem is that Windows has one handle type for everything, while other OS have different types of handles.
?

Mattias

Reply by email

Michael Van Canneyt
to Antonio Fortuny: Le 09/08/2013 11:29, Sven Barth a ?crit : OK, I think I can live with this. But I think…
Antonio Fortuny wrote 29 lines
Le 09/08/2013 11:29, Sven Barth a ?crit : > Am 09.08.2013 11:15, schrieb Antonio Fortuny: >> >> Le 09/08/2013 10:22, Mattias Gaertner a ?crit : >>> clamav3.pas(324,12) Error: Forward declaration not solved >>> "OpenLongFileName(const AnsiString,const LongInt):QWord;" >>> >>> Any comment ? >>> Maybe there is a unit in your implementation uses section that >>> redefines THandle. >> On the declaration (following Ctrl + mouse left click) leads to QWord: >> THandle --> PtrUInt (LCLType) --> QWord (systemh.inc) >> on the implementaion: THnadle --> System.THandle (sysutilf.inc) --> >> THandle --> LongInt (sysosh.inc) >> >> Well done. In the interface units uses declares: LCLIntf, LCLType, >> LMessages, FileUtil; >> In the implemantaion uses declares Classes, sysutils; >> OK. It is a Delphi conversion and I didn't pay enough attention to it >> >> But the isn't there some ambiguity between LCL declarations and FPC >> declarations for what is obviously the same type ? > Might be related to the fact that the LCL often uses the THandle to store a > pointer on non-Windows widgetsets. On e.g. Linux x86_64 THandle is defined > as a longint because of file operations... There might not be a solution > with which anyone can live :/ OK, I think I can live with this. But I think it would be preferable to use a distinct type name.

I have been proponent of this idea since many years :-)

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 8 lines
Michael Van Canneyt hat am 9. August 2013 um 12:19 geschrieben: [...] > OK, I think I can live with this. But I think it would be preferable to use > a > distinct type name. I have been proponent of this idea since many years :-)

What type do you want to rename?

Mattias

Reply by email

Sven Barth
to Mattias Gaertner
Mattias Gaertner wrote 8 lines
> Michael Van Canneyt hat am 9. August 2013 um 12:19 > geschrieben: > [...] >> OK, I think I can live with this. But I think it would be preferable to use >> a >> distinct type name. > I have been proponent of this idea since many years :-) What type do you want to rename?

LCLType.THandle.

Regars,
Sven

Reply by email

Michael Van Canneyt
to Mattias Gaertner: What type do you want to rename? Mattias
Mattias Gaertner wrote 11 lines
> Michael Van Canneyt hat am 9. August 2013 um 12:19 > geschrieben: > [...] >> OK, I think I can live with this. But I think it would be preferable to use >> a >> distinct type name. > > I have been proponent of this idea since many years :-) What type do you want to rename?

THandle. I suspect you have it in lcltypes or so.

IMHO there should be TFileHandle, TWindowHandle etc. Probably on windows they will all end up referencing windows.THandle, but on other platforms they may be wildly different.

That's one of the reasons dynlibs introduced TLibHandle.

Michael.

Reply by email

Antonio Fortuny
to Michael Van Canneyt

Le 09/08/2013 13:39, Michael Van Canneyt a ?crit :

Show quoted text 23 lines
On Fri, 9 Aug 2013, Mattias Gaertner wrote: > >> Michael Van Canneyt hat am 9. August 2013 >> um 12:19 >> geschrieben: >> [...] >>> OK, I think I can live with this. But I think it would be >>> preferable to use >>> a >>> distinct type name. >> >> I have been proponent of this idea since many years :-) > > What type do you want to rename? THandle. I suspect you have it in lcltypes or so. IMHO there should be TFileHandle, TWindowHandle etc. Probably on windows they will all end up referencing windows.THandle, but on other platforms they may be wildly different.

For a developer as me, this is probably the best solution indeed. I do manipulate lots of handles in my applications and do not really want to take care of which basic type they are. I'd be more than happy to re-engineer my applications diversifying handle types which means to get rid of all this ambiguity when addressing OS objects. My problem then would be to use the right handle type where needed

Antonio.

Show quoted text 12 lines
That's one of the reasons dynlibs introduced TLibHandle. Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Michael Van Canneyt
to Antonio Fortuny
Antonio Fortuny wrote 31 lines
Le 09/08/2013 13:39, Michael Van Canneyt a ?crit : > > > On Fri, 9 Aug 2013, Mattias Gaertner wrote: > >> >>> Michael Van Canneyt hat am 9. August 2013 um >>> 12:19 >>> geschrieben: >>> [...] >>>> OK, I think I can live with this. But I think it would be preferable to >>>> use >>>> a >>>> distinct type name. >>> >>> I have been proponent of this idea since many years :-) >> >> What type do you want to rename? > > THandle. I suspect you have it in lcltypes or so. > > IMHO there should be TFileHandle, TWindowHandle etc. Probably on windows > they will all end up referencing windows.THandle, but on other platforms > they may be wildly different. For a developer as me, this is probably the best solution indeed. I do manipulate lots of handles in my applications and do not really want to take care of which basic type they are. I'd be more than happy to re-engineer my applications diversifying handle types which means to get rid of all this ambiguity when addressing OS objects. My problem then would be to use the right handle type where needed

That is exactly why I am a proponent of this mechanism.

Michael.

Reply by email

Antonio Fortuny
to Michael Van Canneyt

Le 09/08/2013 15:02, Michael Van Canneyt a ?crit :

Show quoted text 37 lines
On Fri, 9 Aug 2013, Antonio Fortuny wrote: > > Le 09/08/2013 13:39, Michael Van Canneyt a ?crit : >> >> >> On Fri, 9 Aug 2013, Mattias Gaertner wrote: >> >>> >>>> Michael Van Canneyt hat am 9. August 2013 >>>> um 12:19 >>>> geschrieben: >>>> [...] >>>>> OK, I think I can live with this. But I think it would be >>>>> preferable to use >>>>> a >>>>> distinct type name. >>>> >>>> I have been proponent of this idea since many years :-) >>> >>> What type do you want to rename? >> >> THandle. I suspect you have it in lcltypes or so. >> >> IMHO there should be TFileHandle, TWindowHandle etc. Probably on >> windows they will all end up referencing windows.THandle, but on >> other platforms they may be wildly different. > For a developer as me, this is probably the best solution indeed. I > do manipulate lots of handles in my applications and do not really > want to take care of which basic type they are. I'd be more than > happy to re-engineer my applications diversifying handle types which > means to get rid of all this ambiguity when addressing OS objects. My > problem then would be to use the right handle type where needed That is exactly why I am a proponent of this mechanism.

Just tell me how to push forward with you 8-)

Antonio.

Show quoted text 9 lines
Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/c2d2378b/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: ahbcjfcj.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/c2d2378b/attachment-0002.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: fiaafcib.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130809/c2d2378b/attachment-0003.jpg>

Reply by email

Michael Van Canneyt
to Antonio Fortuny
Antonio Fortuny wrote 11 lines
>>> they will all end up referencing windows.THandle, but on other platforms >>> they may be wildly different. >> For a developer as me, this is probably the best solution indeed. I do >> manipulate lots of handles in my applications and do not really want to >> take care of which basic type they are. I'd be more than happy to >> re-engineer my applications diversifying handle types which means to get >> rid of all this ambiguity when addressing OS objects. My problem then >> would be to use the right handle type where needed > > That is exactly why I am a proponent of this mechanism. Just tell me how to push forward with you 8-)

Simple:
We kidnap Mattias, lock him in the casemates in Luxemburg city, and don't let him out till he did the work ;)

Michael.

Reply by email

Antonio Fortuny
to Michael Van Canneyt

Le 09/08/2013 15:21, Michael Van Canneyt a ?crit :

Show quoted text 20 lines
On Fri, 9 Aug 2013, Antonio Fortuny wrote: >>>> they will all end up referencing windows.THandle, but on other >>>> platforms they may be wildly different. >>> For a developer as me, this is probably the best solution indeed. I >>> do manipulate lots of handles in my applications and do not really >>> want to take care of which basic type they are. I'd be more than >>> happy to re-engineer my applications diversifying handle types >>> which means to get rid of all this ambiguity when addressing OS >>> objects. My problem then would be to use the right handle type >>> where needed >> >> That is exactly why I am a proponent of this mechanism. > Just tell me how to push forward with you 8-) Simple: We kidnap Mattias, lock him in the casemates in Luxemburg city, and don't let him out till he did the work ;)

Looks so simple. OK Michael, look for the chains and the cuffs and I'll take care for a machine gun. Who's gonna take the car ? Maybe a bicycle would do it ? :-P

Antonio.

Show quoted text 9 lines
Michael. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Santiago Amposta
to Antonio Fortuny: Le 09/08/2013 10:22, Mattias Gaertner a ?crit : On the declaration (following Ctrl +…

El 09/08/2013 11:15, Antonio Fortuny escribi?:

Show quoted text 5 lines
But the isn't there some ambiguity between LCL declarations and FPC declarations for what is obviously the same type ? Thanks Mattias,

In delphi, exists sysutils.abort and windows.abort. I don't know how long it took me to find the bug: Just because "windows" was used after "sysutils". In this case the compiler didn't complain, and the errors where very weird.

Other languages, like Ada, raise a compiler error. IMHO, the FPC should not allow such ambiguity and raise an error, asking to qualify the identifier. I suppose it would break backward compatibility, a directive {$Check_Ambiguity+} would be fine for me ;-)

When you work with big programs, you are going to face with identifier collisions. The solution is not to change identifier, probably each unit programmer chose such name for good reasons, but using namespaces, that object pascal already has. The current solution, relying in the order of units to guess which one will pick, is a prone of errors, and sometimes very difficult to find, because most of us aren't aware of this most time, and don't code with this concept in mind. With hundreds of third party libraries and components, I am sure many people have hit this error and gone nuts for a while.

The reason why things like this don't happen more often is because units usually contain objects and we use things encapsulated in object more often than global identifiers. But that is not an excuse, relying in "uses" order is a poor decision from old times that could be improved.

Sure it's a FPC topic, but I couldn't help... it's just a rant ;-)

Un saludo Santiago A.

Reply by email

Marcos Douglas
to Santiago Amposta
Santiago Amposta wrote 16 lines
El 09/08/2013 11:15, Antonio Fortuny escribi?: > > But the isn't there some ambiguity between LCL declarations and FPC > declarations for what is obviously the same type ? > Thanks Mattias, > In delphi, exists sysutils.abort and windows.abort. I don't know how long it took me to find the bug: Just because "windows" was used after "sysutils". In this case the compiler didn't complain, and the errors where very weird. Other languages, like Ada, raise a compiler error. IMHO, the FPC should not allow such ambiguity and raise an error, asking to qualify the identifier. I suppose it would break backward compatibility, a directive {$Check_Ambiguity+} would be fine for me ;-)

+1

Show quoted text 16 lines
When you work with big programs, you are going to face with identifier collisions. The solution is not to change identifier, probably each unit programmer chose such name for good reasons, but using namespaces, that object pascal already has. The current solution, relying in the order of units to guess which one will pick, is a prone of errors, and sometimes very difficult to find, because most of us aren't aware of this most time, and don't code with this concept in mind. With hundreds of third party libraries and components, I am sure many people have hit this error and gone nuts for a while. The reason why things like this don't happen more often is because units usually contain objects and we use things encapsulated in object more often than global identifiers. But that is not an excuse, relying in "uses" order is a poor decision from old times that could be improved. Sure it's a FPC topic, but I couldn't help... it's just a rant ;-)

Namespaces was discussed many times on FPC list and many ideas were said, however no idea was good enough for FPC team, unfortunately.

Regards,
Marcos Douglas

Reply by email

Hans-Peter Diettrich
to Santiago Amposta: El 09/08/2013 11:15, Antonio Fortuny escribi?: In delphi, exists sysutils.abort and…
Show quoted text 15 lines
El 09/08/2013 11:15, Antonio Fortuny escribi?: > But the isn't there some ambiguity between LCL declarations and FPC > declarations for what is obviously the same type ? > Thanks Mattias, > In delphi, exists sysutils.abort and windows.abort. I don't know how long it took me to find the bug: Just because "windows" was used after "sysutils". In this case the compiler didn't complain, and the errors where very weird. Other languages, like Ada, raise a compiler error. IMHO, the FPC should not allow such ambiguity and raise an error, asking to qualify the identifier. I suppose it would break backward compatibility, a directive {$Check_Ambiguity+} would be fine for me ;-)

Some more people would like something like that. The compiler developers most probably won't, because it would slow down compilation.

As a compromise a directive $RequireQualification could be added, forcing error messages with *all* unqualified identifiers in the unit. This in fact could speed up compilation, because searching the Uses lists is not required any more. But before using such an switch a tool or feature would be required to qualify all unambiguous identifiers, and to offer choices for the ambiguous ones.

A global directive won't work, because the FCL, LCL and all other library writers most probably won't update their code, only to please some users. And I wouldn't like that, too, because it adds so many qualifiers to the code, that it will become almost unreadable to me (and other coders).

Sure it's a FPC topic, but I couldn't help... it's just a rant ;-)

Ask again in FPC-devel, or create an feature request.

Or write your own tool for finding ambiguous declarations, and the whole world will praise you ;-)

DoDi

Reply by email

Mattias Gaertner
to Michael Van Canneyt: Simple: We kidnap Mattias, lock him in the casemates in Luxemburg city, and don't let him…
Show quoted text 18 lines
On Fri, 9 Aug 2013, Antonio Fortuny wrote: >>>> they will all end up referencing windows.THandle, but on other platforms >>>> they may be wildly different. >>> For a developer as me, this is probably the best solution indeed. I do >>> manipulate lots of handles in my applications and do not really want to >>> take care of which basic type they are. I'd be more than happy to >>> re-engineer my applications diversifying handle types which means to get >>> rid of all this ambiguity when addressing OS objects. My problem then >>> would be to use the right handle type where needed >> >> That is exactly why I am a proponent of this mechanism. > Just tell me how to push forward with you 8-) Simple: We kidnap Mattias, lock him in the casemates in Luxemburg city, and don't let him out till he did the work ;)

Do casemates have power and internet?

Mattias

Reply by email