Hello everybody.

Here next episode of the conversion of a useful fp unit into a universal 
library...

The goal is to make a library from a unit used by programs.
That unit has lot of complicated procedures-functions, inside some home-made 
classes, using many dynamic arrays who vary in length and data in real time. 
Also that procedures call other procedures from foreign dynamic loaded 
libraries and sent it back to other foreign libraries (after some modification 
by self-unit of course).

Lets call that unit 'myunit'.

Here first working steps: please advice if im on the wrong way... Many thanks.

1) Create a new file, name it mylib.pas and add this :

library mylib ;

use
myunit; /// the famous unit with all the procedures/functions, classes,...

begin
end.

(You have already done all the work !)

2) Add the functions-procedures you want from myunit in your library-code:

- Here example for general procedure, not inside a class:

library mylib ;

uses
myunit;

procedure mylibprocedure(); cdecl;
begin
  myunit.myprocedure(); /// a general procedure
end; 

exports  
mylibprocedure ;
 
begin
end.

- Here example for function inside a class of myunit:

library mylib ;

uses
myunit;

function mylibclassfunction() : integer; cdecl;
var
myclass : TMyUnitClass; /// class defined in myunit (if can be a variable 
outside the function)

begin
   result := -1 ;
   myclass := TMyUnitClass.Create;  
   result := myclass.myunitclassfunction() ; // a function of myclass  
end;

exports  
mylibclassfunction ;
 
begin
end.

3) Add this compiler option : -fPIC (otherwise it does not compile on my 64 bit 
Linux)

4) Cross your fingers and compile it.

... And you know what : it compiles and it works ! 

I’m very happy with fpc, all is simple and accessible.

And, with the recent optimizations, fpc is formula 1 (f1pc)...

...............

Now the boring question : 
Is it normal, even without debug-infos, with -Xs parameters, stripped,... that 
this library :

Library test ;
begin
end;

is 200k big ! ( mine, nude, only with "uses uos" is more than 1 mega ! ).

Many thanks for wonderful f1pc.

Fred
                                          
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to