Hi!
I'm doing a Library which reads data from a serial port connected hardware and send the collected data to a remote server. The server sends a confirmation which the library returns to the application and the process ends.
The library is pretty simple, never the less I started to have Access Violations and SigSegs. These exceptions desapeared when I use the working class (the one which the library use) directly from the form, the application worked smoothly.
Then I removed a Callback the application passed to the library to update the form with a text describing the job's execution state. to see if this solved the problem but, it didn't.
After that I decided to do a Test Library Project to explore what I can do with the library and the errors I might get without having to recompile the app and library. I included in the project everything I thought could cause the exception: like a complex output and a Callback and I found something strange (or at least unexpected for me):
o- AV is thrown when the library's output includes a String created or modified by the librarary.
o- AV is thrown when the library's output includes a Dynamic Array.
o- AV is thrown when the library use a Callback passed by the Form.
Now comes the question:
Did I do something wrong?
Can I export an object created inside the library?
Why I can't execute a Callback inside the Library?
A few more questions:
Is there any good library Tutorial?
Is there any good PChar Tutorial? The only examples I found were in "strings" unit's help, and there was nothing to convert very long pascal strings to PChar so I made my own, but I don't know if there's something alredy made in FPC.
I attached the test library project and the GUI to use it. Please test it using the different options (mtNone, mtString, mtArray, mtPChar) and confirm if you have an AV when message Type is mtString or mtArray or when use notify event.
This post is derived from
this thread.
Using Lazarus 1.1 SVN Revision: 40379 Date:2013-04-09 FPC: 2.6.2 on Windows XP. But the solution must be crossplatform.