* * *

Author Topic: [Solved] Package does not show its members  (Read 612 times)

mb

  • New member
  • *
  • Posts: 5
[Solved] Package does not show its members
« on: June 23, 2018, 12:26:22 pm »
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  [Select]
  1. unit Unit2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils;
  9.  
  10. type
  11.         // the type TRandomNumber gets globally known
  12.         // since it is included somewhere (uses-statement)
  13.         TRandomNumber = integer;
  14. implementation
  15.  
  16. 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  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, PackageTest;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.   private
  13.  
  14.   public
  15.  
  16.   end;
  17.  
  18. var
  19.   Form1: TForm1;
  20. implementation
  21.  
  22. {$R *.lfm}
  23.  
  24. var
  25.         chosenRandomNumber: TRandomNumber;
  26.  
  27. end.

But now I cant define type of "TRandomNumber", compiler says
Quote
unit1.pas(27,25) Error: Identifier not found "TRandomNumber"
.

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.
« Last Edit: June 24, 2018, 09:33:39 am by mb »

PascalDragon

  • Full Member
  • ***
  • Posts: 203
  • Compiler Developer
Re: Package does not show its members
« Reply #1 on: June 23, 2018, 01:48:53 pm »
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

  • New member
  • *
  • Posts: 5
Re: Package does not show its members
« Reply #2 on: June 23, 2018, 06:42:00 pm »
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.
« Last Edit: June 23, 2018, 06:47:53 pm by mb »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus