Forum > Beginners

[Solved] Package does not show its members

(1/1)

mb:
Hello,

coming from C# I tried to play a little with FPC.

Having problems with packages and couldnt find much stuff around that explains a little details:

1. I created a new project as package.
2. I created a unit with a single type:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils; type        // the type TRandomNumber gets globally known        // since it is included somewhere (uses-statement)        TRandomNumber = integer;implementation end.
3. Set package to "Runtime" since I only wanna import the code into the project, not into UI.
4. Compiled package without any errors or messages -> named: "PackageTest".
5. Created another project.
6. Added my package to project within project-inspector.
7. Added package-name to uses-clause of my project (works without flaws).


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, PackageTest; type  TForm1 = class(TForm)  private   public   end; var  Form1: TForm1;implementation {$R *.lfm} var        chosenRandomNumber: TRandomNumber; end.
But now I cant define type of "TRandomNumber", compiler says
--- Quote ---unit1.pas(27,25) Error: Identifier not found "TRandomNumber"
--- End quote ---
.

Also with a second package I did before, I cant access anything from inside my packages.

What am I doing wrong?
Are there any paths I have to set additionaly? I thought importing my package within project-inspector is enough, also it seems to recognize my package by name, but not any of its members.

PascalDragon:
Packages as used by Lazarus are not like Assemblies provided by .NET. They are "merely" wrappers to compile the contained units only once. To make use of the units inside a package you need to use the specific units themselves (the unit of the package is only there for compiling the package) in addition to adding the package to the project (adding a package to the project essentially adds the package's unit path to the project, so that the compiler can find the compiled units).

So in your case you'd need to add unit Unit1 to your uses-clause in Unit2.

mb:
Thank you very very much, also for your detailed explanation, that solved my problem.
Adding Unit2(from package) into my Unit1(project) solved my problem.

I thought this is not necessary, because all units are included in unit-clause of that package-unit, but it makes sense that it works this way. Other units of a package are not passed-through this package-unit.

Thanks again for this great help !!

I bought 3 books for FPC and Lazarus, but no where (even on YouTube) I found such an easy explaination or way how to use those units you "combined" in a package.

Navigation

[0] Message Index

Go to full version