[Gambas-user] How to make Class file to Library for use in other Gambas applications

GMail adamnt42 at ...626...
Wed Feb 22 02:22:10 CET 2012


On Wed, 2012-02-22 at 01:03 +0100, Willy Raets wrote:
> Hi all,
> 
> I've been searching and reading my butt of on how to make a library with
> Gambas 2 for Gambas 2.
> 
First, gambas 2 does not have "libraries", what you are creating is a
"gambas component".  A pedantic point perhaps, but gambas 3 libraries
are quite a different kettle of fish.

> It is a very simple and short library so I can get familiar with how it
> works and do a how to documentation so others can benefit of my learning
> curve as well and you will be bored less with questions like this on
> this list (hopefully).
> 
> I have a simple Class called SysInfo (made it Start up Class)
> That is all the project contains, no forms or modules.
> 
> ------ Code for Class SysInfo ---
> 

(As Jussi says)
EXPORT

> PUBLIC OS AS String
> PUBLIC Kernel AS String
> PUBLIC KernelRelease AS String 
> PUBLIC KernelVersion AS String 
> PUBLIC Architecture AS String 
> 
> PUBLIC SUB ReadInfo()
> 
>   DIM sLineOSYS, sLineKERN, sLineKERNR, sLineKERNV, sLineARCH AS String
>   '--- Read system information ---
>   EXEC ["uname", "-o"] TO sLineOSYS
>   EXEC ["uname", "-s"] TO sLineKERN
>   EXEC ["uname", "-r"] TO sLineKERNR
>   EXEC ["uname", "-v"] TO sLineKERNV
>   EXEC ["arch"] TO sLineARCH
>   OS = Trim(sLineOSYS)
>   Kernel = Trim(sLineKERN)
>   KernelRelease = Trim(sLineKERNR)
>   KernelVersion = Trim(sLineKERNV)
>   Architecture = Trim(sLineARCH)
> 
> END
> 
> ----- End Code Class file -----
> 
> Now I read somewhere you need to make a gambas executable and place it
> in the project folder of the project you want to use it.
> 
> So I made an executable named it SysInfo.gambas
> Placed it in the project folder of a project where I need the library
> and then I get stuck.

That is for gambas3.  For gambas2 (from memory) you just need to:
1) in the Project Properties on the Options tab, set "This project is a
component" to Yes and "Component Advancement" to whatever you like.
2) on the "Requires" tab, add any features and components that your
component MUST have access to in order to run as a component in a client
application.  N.B. the Requires tab is different to the Components tab.
3)Make the executable.(Ctl+Alt+M) MAKE SURE THAT YOU CHECK THE "Install
in the User Component Directory" in the Options expander on the Make
Executable form. Then check that the project library contains some new
files: .info, .list and .component (these are used to describe the
component to clients/gb2 runtime.

> 
> How to I use the library in my code?
4) in your client project, On the Project Properties "Comonents" tab you
should see your component listed under the "User Components" section.
(If it's not visible, try opening the project in a completely new
instance of gambas2 IDE)

> 
> Gambas documentation goes into C libraries but says nothing about gambas
> libraries.
> Does it work the same for Gambas libraries, because I have tried with
> using LIBRARY "SysInfo.gambas" and I am not getting there.
> And if I would do EXTERN ReadInfo() compiler gives no problem.
> But how to get the OS because EXTERN OS is not okay for the compiler.
> 
Wrong way go back.  You are correct below.

> I was expecting, because of the library being Gambas for Gambas that it
> would be eazier. Like that the compiler would recognize SysInfo and that
> a simple SysInfo.ReadInfo would run the getting of the info and a simple
> SysInfo.OS would give me the OS info.
> But obviousily it ain't that simple.
Yes it is.
> 
> How do I get my application to recognize SysInfo?
> And next, how do I use SysInfo in my application
> 
> I am missing some information there? 
> Any links to some good example maybe that could get me on the road again
> or some hints?
> 
> Thanks,
> 
> Willy

hth
Bruce





More information about the User mailing list