[fpc-devel] Call initialisation of library automatically in unit-initialization?

Martin Friebe martin at hybyte.com
Wed Dec 3 16:06:29 CET 2008


Joost van der Sluis wrote:
> Op woensdag 03-12-2008 om 13:09 uur [tijdzone +0100], schreef Michael
> Van Canneyt:
>   
>> On Wed, 3 Dec 2008, Joost van der Sluis wrote:
>>
>>     
>>> When you use the MySQL client, you have to call myslq_library_init to
>>> initialise the library, and mysql_library_end to de-initialize it again.
>>>
>>> When the library is dynamically loaded using mysqlXXdyn.pp, shall I call
>>> these functions automatically? Or should we leave it to the programmer?
>>> (I'm in favour of doing it automatically)
>>>       
>> Are there any options to these calls ?
>>
>> If there are, it is a no, I think ?
>>     
>
> Didn't thought about that. And yes, there are options. They are in
> practice only used with the embedded-mysql version. And iven in that
> case I guess they are rarely used: 
>   
....
> So, what to do?
>
>   
There is another option. You can keep track if the user called it. If 
the user did not call it, but any other function is called, then call it 
yourself

procedure MaybeCallInit;
begin
  if InitCalled then exit;
  DoCallInit(0, nil, nil);
  InitCalled := True;
end;

Well it will be more complex, as if this is in a multi threaded 
environment you have to keep track for each Thread. That is unless the 
library is loaded and initialized before any threads are spawned...

Best Regards
Martin





More information about the fpc-devel mailing list