开发者

Delphi, can't use a function in an external .pas file

I am using functions from an external .pas file. I can use some of the functions, but not others. As far as i can see the functions are declared the same way, I would like to post some of the file, but开发者_如何学Python don't know ho to post large amounts of code.


You can use the functions that are declared in the interface section, that is the section of code before the implementation section.

You are probably trying to call functions that are defined only in the implementation section, that is that code that appears after the implementation keyword.

These different sections are how Delphi implements public and private visibility at the unit level.

Usually, in well written units, there will be a reason for functions being made private to the unit. But if you feel it reasonable to override the author's decision then you need to redeclare the function in the interface section. This will make it available to your code which uses the 3rd party unit.


The file is not properly linked and/or not included in your projects search path and/or shadowed by some other file with same function names and/or odd functions are within $IFDEF clauses.

Check spelling, uses clauses, working function location (Ctrl+click on function name in your code), $IFDEF clauses.

  1. The file is not properly linked in Delphi environment options
  2. The file could be located outside of project search path. Hence it's not linked.
  3. The file path is typed wrongly in project (DPR file). E.g. you are referring to older path with olde version of a file.

In each of these cases some functions could be taken from other files if name fits. E.g. function gluUnproject can be taken both from OpenGL.pas and dglOpenGL.pas, if first unit is not linked properly I would get the same problem as you are having now - some functions work and some are missing. In any of the cases you should compile your project, Ctrl+Click on a working function name and see where it brings you, check file version location.

  1. The functions could be inside of $IFDEF clauses. These are compiler directives and code within such clause will be invisible to compiler if certain condition is not met. E.g. {$IFDEF MSWindows} Func {$ENDIF} won't be accessible on Linux.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜