Recent

Author Topic: Installing LMath into the IDE  (Read 5319 times)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Installing LMath into the IDE
« Reply #15 on: August 28, 2021, 07:55:42 pm »
The only thing I did to the default configuration of the new project was add "LMath" to the unit1 uses list.  When I tried to run this new project, it halted with this message:

 "Compile Project, Target: C:\Users\Bert\AppData\Local\Temp\project1.exe: Exit code 1, Errors: 1
unit1.pas(8,58) Fatal: Can't find unit LMath used by Unit1"

What am I missing? 
Did you read what I was writing? You must add LMath to the requirements of the project (in the Project Inspector), not to the uses list. Only when you have done this your project knows about the units contained in LMath. Then select the unit(s) of LMath from which you want to call procedures and add them to the uses list.

I cannot be more specific because I don't know what you need from LMath. But here is a very simple example to show you the steps to create a GUI project for LMath (the final project is in the attachments):
  • create a new GUI project ("File" > "New" > "Project" > "Application")
  • Open the project inspector ("Project" > "Project inspector").
  • Click on "Add" in the project inspector, then "New requirement"
  • In the listbox of the dialog which appear, select "LMath" and press "OK" --> "LMath" appears in the treeview of the project inspector under node "Required Packages"
  • Now suppose you want to calculate the factorial of a number with the aid of the LMath library. There is a function Fact(N : Integer) : Float in unit ufact. So, add "ufact" to the uses clause of the unit1 (the unit with the main form). This is possible now because LMath is listed as a requirement.
Code: Pascal  [Select][+][-]
  1. interface
  2.  
  3. uses
  4.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  5.   ufact;  
  • Add a button to the form, double-click on it to add an event handler for the OnClick event and enter the following code which calculates the factorial for the number 100 and displays the result in a message box
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ShowMessage(FloatToStr(Fact(100)));
  4. end;

This works - tested with Laz 2.2RC1/64 bit.
« Last Edit: August 28, 2021, 08:04:15 pm by wp »

Bert_Plitt

  • Jr. Member
  • **
  • Posts: 62
Re: Installing LMath into the IDE
« Reply #16 on: August 28, 2021, 10:05:00 pm »
The project you sent works OK on my machine.  Thanks for sending it.  I see that in addition to adding LMath to Required Packages in the Project Inspector, you added ufact to the project uses list.  That's what I've been missing.  I thought I read somewhere that one of the feature of the latest version of LMath was that when you add LMath as a required package to a project, you no longer had to list all the "sub-packages" the project needs.   Evidently, that's not the case.  For my math application, I declare variables of  type complex.  So, I'll have to add uTypes (the unit in which type "complex" is declared) to the uses list.

WP, I think I now understand.  Thanks very much for your patience.  You have been very helpful.
Windows 10, Lazarus 2.2.2, FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Installing LMath into the IDE
« Reply #17 on: August 28, 2021, 10:36:29 pm »
I thought I read somewhere that one of the feature of the latest version of LMath was that when you add LMath as a required package to a project, you no longer had to list all the "sub-packages" the project needs.   Evidently, that's not the case. 
Having LMath in the requirements of the project that I sent does not mean that the project knows in which unit the factorial function of my sample resides.

Lazarus requires two steps: (1) add the package to the project requirements, (2) add a unit out of this package to the uses list of a project unit.

Maybe it is confusing that there is a package (LMath) which "contains" other packages. One of these "sub-packages" is lmGenMath with elemental math routines - one of them is the lmFact package of my sample project. Since only this function of LMath is used in my example you could also have added the package lmgenmath to the project requirements tree (instead of lmath). But when the project grows and maybe later needs a fitting routine from the lmRegression package this packages would have to be added to the requirements as well. Having added the LMath package, however, makes all these sub-packages available to your project, so that you no longer must care about these details.

Bert_Plitt

  • Jr. Member
  • **
  • Posts: 62
Re: [SOLVED] Installing LMath into the IDE
« Reply #18 on: August 29, 2021, 04:51:53 am »
WP — Thanks again for your explanation.  I now understand that if something contained in one of the LMath packages is needed in a project, the unit in which it resides must be included in the uses list.  I modified my math project and now it compiles and runs as before my PC crash.  The issue is now closed.  Again, thanks for your patients and help.
« Last Edit: August 29, 2021, 06:39:32 pm by Bert_Plitt »
Windows 10, Lazarus 2.2.2, FPC 3.2.2

 

TinyPortal © 2005-2018