[fpc-pascal] A better way?

2016-04-13 Thread Ryan Joseph
The most annoying problem I have with Pascal currently is with circular unit 
dependanices and “global” classes that need to be referenced from many units. 
In other languages I would make a forward declaration of the class in  one file 
then implement it in another file so that all files could reference the class. 
It’s maybe a symptom of a “bad" design but sometimes it’s just faster and 
easier so it’s a problem I have to fight Pascal to make it work.

When I moved to FPC the solution I started using was this pattern below where I 
make an abstract class then override the methods I need in the global namespace 
within in the “main unit”. This is a bad hack to workaround a feature of the 
language but I wonder if there’s a better way. Does anyone have any ideas I 
could try?



"global” unit shared by many other units:

type
  TSomeClassAbstract = class (TObject)
procedure DoSomething; virtual; abstract;
  end;
  
“main” unit which implements the class:  
  
type
  TSomeClass = class (TSomeClassAbstract)
procedure DoSomething; override;
  end;


Regards,
Ryan Joseph

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

Re: [fpc-pascal] Initialization in Shared Libraries

2016-04-13 Thread Sven Barth
On 13.04.2016 21:30, Mazola Winstrol wrote:
> 2016-04-13 15:56 GMT-03:00 Jonas Maebe  >:
> 
> 
> And hence you can just initialise those variables in the
> initialization section of the library and finalize them (if
> necessary) in the finalization section of the library.
> 
> 
> Thanks!
> 
> Can i use class constructors in shared libraries? Does unit's
> initialization section and class constructors have the same behaviour in
> all platforms and the same when compared with a normal program?

Yes and mostly yes. The finalization sections might not be called in the
context of the same thread as the initialization sections, because if
the thread that does the last unload of the library (if it is
dynamically loaded) then it's called in that thread's context. But other
then that they behave the same as for normal programs.

Regards,
Sven

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


Re: [fpc-pascal] Initialization in Shared Libraries

2016-04-13 Thread Mazola Winstrol
2016-04-13 15:56 GMT-03:00 Jonas Maebe :

>
> And hence you can just initialise those variables in the initialization
> section of the library and finalize them (if necessary) in the finalization
> section of the library.
>
>
Thanks!

Can i use class constructors in shared libraries? Does unit's
initialization section and class constructors have the same behaviour in
all platforms and the same when compared with a normal program?

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

Re: [fpc-pascal] Initialization in Shared Libraries

2016-04-13 Thread Jonas Maebe

Michael Van Canneyt wrote:



On Wed, 13 Apr 2016, Mazola Winstrol wrote:


I writting a cross-platform shared library (.dll, .so). I need to
initialize some global variables.

As the free pascal doesn't support library events (PROCESS_ATTACH,
PROCESS_DETACH), what is the correct to way to do this?


It does, but it catches them in the system unit; I do not think they are
exposed.


And hence you can just initialise those variables in the initialization 
section of the library and finalize them (if necessary) in the 
finalization section of the library.



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


Re: [fpc-pascal] Initialization in Shared Libraries

2016-04-13 Thread Mazola Winstrol
2016-04-13 15:52 GMT-03:00 Michael Van Canneyt :

>
>
> On Wed, 13 Apr 2016, Mazola Winstrol wrote:
>
> Hello list,
>>
>> I writting a cross-platform shared library (.dll, .so). I need to
>> initialize some global variables.
>>
>> As the free pascal doesn't support library events (PROCESS_ATTACH,
>> PROCESS_DETACH), what is the correct to way to do this?
>>
>
> It does, but it catches them in the system unit; I do not think they are
> exposed.
>
>
So, what is the correct way to initialize global variables? In a normal
program i can use unit's initialization section or class constructors. But
the documentation is not clear about the the case of shared libraries.

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

Re: [fpc-pascal] Initialization in Shared Libraries

2016-04-13 Thread Michael Van Canneyt



On Wed, 13 Apr 2016, Mazola Winstrol wrote:


Hello list,

I writting a cross-platform shared library (.dll, .so). I need to
initialize some global variables.

As the free pascal doesn't support library events (PROCESS_ATTACH,
PROCESS_DETACH), what is the correct to way to do this?


It does, but it catches them in the system unit; I do not think they are
exposed.

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


[fpc-pascal] Initialization in Shared Libraries

2016-04-13 Thread Mazola Winstrol
Hello list,

I writting a cross-platform shared library (.dll, .so). I need to
initialize some global variables.

As the free pascal doesn't support library events (PROCESS_ATTACH,
PROCESS_DETACH), what is the correct to way to do this?

best
ragrds
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] TP lex change input buffer

2016-04-13 Thread leledumbo
> I'm using TP lex in my application and I would like to change the input
buffer from using files to (memory) strings. What is the supposed way to do
this?

>From the comments:
"The variables yyinput and yyoutput are the text files which are used
by the lexical analyzer. By default, they are assigned to standard
input and output, but you may change these assignments to fit your
target application (use the Turbo Pascal standard routines assign,
reset, and rewrite for this purpose)."

Thankfully, we also have:
http://www.freepascal.org/docs-html/3.0.0/fcl/streamio/index.html

Which can turn any TStream descendant into a TextFile. Just change Assign as
in the comment above into AssignStream, everything else is totally the same.



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/TP-lex-change-input-buffer-tp5724893p5724895.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC 3 regression: cannot use TStringList for UTF-8 data any more?

2016-04-13 Thread Michael Van Canneyt



On Tue, 12 Apr 2016, Michael Schnell wrote:


On 04/04/2016 11:27 AM, Juha Manninen wrote:
Just use the new UTF-8 mode provided by Lazarus and remove all explicit 
conversion functions. 
http://wiki.freepascal.org/Better_Unicode_Support_in_Lazarus
I just did some tests and it seems that TStringList (this is what Tobias is 
concerned about) (with the Lazarus installation straight from the svn) 
seemingly always uses UTF8.


Is this correct  ?


No. It uses the DefaultSystemcodepage. If the system codepage is UTF8, then
it will use UTF8.

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


[fpc-pascal] TP lex change input buffer

2016-04-13 Thread Darius Blaszyk
Hi,

I'm using TP lex in my application and I would like to change the input
buffer from using files to (memory) strings. What is the supposed way to
do this? Currently I have made a local copy of lexlib and modified the
get_char (and friends) routine. However this does not seem to be the
ideal way to do it, although the comments in lexlib seem to indicate
otherwise.

Regards, Darius

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

Re: [fpc-pascal] FPC 3 regression: cannot use TStringList for UTF-8 data any more?

2016-04-13 Thread Michael Schnell

On 04/04/2016 11:27 AM, Juha Manninen wrote:
Just use the new UTF-8 mode provided by Lazarus and remove all 
explicit conversion functions. 
http://wiki.freepascal.org/Better_Unicode_Support_in_Lazarus
I just did some tests and it seems that TStringList (this is what Tobias 
is concerned about) (with the Lazarus installation straight from the 
svn) seemingly always uses UTF8.


Is this correct  ?

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