Using Delphi component under C++ Builder makes calls to a wrong function - function

I'm trying to use Graphics32 package. Graphics32 was compiled and installed without any issue.
When I try to execute (debug) following code under C++ Builder XE3
TBitmap32* bmp = new TBitmap32();
bmp->LoadFromFile("d:\\sample.bmp");//This calls SaveToStream instead of LoadFromFile
...
it calls another member function SaveToStream which I can trace into and step while debugging until AV rises.
I have never encountered such behavior before.
Is there any compiler directive I'm missing or some workaround to make proper function call?
Update: I use the Graphics32 source from SVN. Everything works good if I use code prior to revision 2122.

Related

F# Guid.Parse TypeInitializationException

I'm working on a WebApi project written in F#. Here a snippet:
module MyModule
open System
let MyGuid = Guid.Parse "934F0B12-D00A-491D-862D-EE745EF3C560"
let myFunction list =
list.Get(MyGuid) // --> here MyGuid has the TypeInitializationException before list.Get is called
By debugging I can see that the MyGuid actually has an error
Changing the code followings, it works:
module MyModule
open System
let MyGuid () = Guid.Parse "934F0B12-D00A-491D-862D-EE745EF3C560"
let myFunction list =
list.Get(MyGuid())
I actually know the MyGuid of the first example is a variable and the second one a function definition, but why does the first rise the exception? I my code MyGuid is used some times. so in the first example I'd have only one instance, in the second a new instance every time MyGuid is called...
I'm not 100% sure that this is the problem here, but I've seen similar behaviour when using unit test runners sometimes. My guess is that the error happens because the top-level MyGuid variable is not initialized correctly and has the default zero value (and as a result, the lookup fails).
The way global variables are initialized in F# is tricky - if you compile code as executable, this can happen from the Main method. But if you compile code as a library, the compiler inserts an initialization checks into static constructors of the types in your library (to make sure everything is initialized before you access anything).
I think this can break if you compile your code as an executable, but then load it as a library - the entry-point is not called and so the variables are not initialized. I'm not sure how exactly WebApi loads libraries, but this could be a problem - especially if you compile the F# code as an executable.
Your workaround of turning the global variable into a function fixes this, because the function is compiled as a method and so you avoid referring to an uninitialized value. Sadly, I don't think there is a better workaround for this.

Make PhpStorm add a warning if calling a function with more arguments than declared

Using PhpStorm 8.0.3.
Let's say I have this function:
public function myFunction($argA, $argB) {
// ...
}
And I'm calling it from somewhere else in the project with one extra argument, like:
$myClass->myFunction($arg1, $arg2, $arg3);
I know this is not considered an error in PHP, and it can be useful in some scenarios... but it is wrong according to my own coding standards, so I just wanted to know if there's a way to make PhpStorm to warn me if I'm doing it somewhere...
You cannot do anything about it in PhpStorm v8.0.3.
But PhpStorm v9 already has separate inspection for that. If you want -- try v9 EAP build now.

Strange errors when linking to libmariadb

I'm currently develop an Objective-C library that links to the MariaDB C connector. I believe there is a problem with the library, though.
Every time I execute my code I get very strange errors on the console. The -(id)init method of my library calls mysql_init(NULL) to initialise the library but as soon as I return from -(id)init I get the following errors in the console:
Object 0x10643df70 of class XXX autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Thing is, there is no multithreaded code being executed and if I run the same - (id)init without the call to mysql_init(NULL) the errors disappear. I believe the libmariadb library is causing these errors to appear. I don't get why though.
Do I need to build it with any special command line switches? Am I calling the right methods? I obviously used the MySQL online documentation as a guide.
Make sure you add this anytime you have a new thread:
#autoreleasepool {
//enter code here
}
Have you tried latest revision from launchpad?
Also try to build libmariadb with -DUNDEF_THREADS_HACK and
CMAKE_USE_PTHREADS:BOOL=OFF)
I was busy with other stuff for a while. I've since updated MariaDB to the latest version and, as far as I can tell, it works fine.

TypeScript 'var' is undefined error

I built a console app to find all the *.ts files in my project and then compile them using tsc.exe.
Everything was working fine, but as I converted my JavaScript files to TypeScript, I eventually ran into the following error:
ytsc.js(21053, 17) Microsoft JScipt runtime error: 'window' is undefined
Each time this happened when I was trying to extend window:
window['prop'] = "something";
I tested the code until I found the answer, which had little to do with my code...
The fault was my build tool.
I had declared the -e (execute) command line option when calling tsc.exe:
I did this because I thought I might add some automated testing code in the modules.
The cause for the error:
Most of my code is in functions.
However, there were a few places that I wanted to extend 'window' (for example if a built in function is missing from an old browser, I was shimming those calls). The code to shim the window object was running as the file loaded:
if (window.fun == null) {
window.fun = function(){...};
}
Anyway, because of the -e option, the tsc.exe was attempting to run the code (outside of a browser environment). This caused the above error.

Referencing and using JScript.NET "functions only" exe assembly

1. Compiled Assembly from JSC
I've compiled what is intended to be client-side JavaScript using the JScript compiler (jsc.exe) on the server side in an attempt to make something that can be tested from a unit testing project, and maybe even something that can be debugged on the server side.
The compiled file contains only functions as follows (just for example) and it compiles fine into BitField.exe. Notice, no wrapper class or package in the source code.
------ BEGIN FILE (BitField.js) -------
function BitField(){
this.values = [];
}
// more functions ...
------- END FILE -------
jsc /fast- /out:BitField.exe Bitfield.js
Results in a BitField.exe assembly.
Success! Well, kind of ....
2. Testing Assembly / Access Point?
Secondly I've created a test project (in C#) and referenced in the BitField.exe assembly successfully. (The type of project is irrelevant but I'm providing more description to paint a full picture.)
The problem seems to be: I cannot find the namespace or a point at which I can access the BitField functions inside the BitField.exe assembly from my C# test project. The assembly doesn't seem to be a "normal".
In other words I need in C#
using ???WHAT???
Note: I don't want to use JScript "extensions", meaning keywords that won't run client-side (in a web browser), for example, class, package etc because I want the code to be clean as possible for copy & paste back into client side script environment (Regardless said "clean" code compiles fine by jsc.exe without use of those extensions). When I try to wrap the functions in package and class it starts producing compile errors so that's another reason not to use them - because they appear to make me alter my code.
Any suggestions as to how I can use the functions of the compiled JScript assembly (by having it referenced into another assembly) when there are no explicit containers in it?
Update / Proof
.NET Reflector view
After playing around with it for a while, and trying various combinations of command-line switches for jsc.exe, I'm pretty sure that what you're trying to do won't work as you'd wish it to. If you try to compile a js file that contains functions into a .Net library assembly, you get an error:
BitField.js(1,1) : error JS1234: Only type and package definitions are allowed inside a library
But, there is hope, yet! Here's what I would do...
I would keep your "clean" BitField.js file just as it is, and then create a batch file that wraps it in a JScript class and writes it out to a "dirty" js file. It's pretty clean if you think of it as part of the compilation of the code into the DLL. The code to wrap the BitField.js into BitFieldClass.js would look like this:
merge-into-class.js
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1;
var inputFile = fso.OpenTextFile("BitField.js",ForReading, false);
var outputFile = fso.CreateTextFile("BitFieldClass.js", true);
outputFile.write("class BitFieldClass{\n");
while (!inputFile.AtEndOfStream)
{
var textLine = inputFile.ReadLine();
outputFile.write (textLine + "\n");
}
outputFile.write("}");
outputFile.close();
Then the batch file to wrap it and compile it is really simple:
compile-js.bat
cscript merge-into-class.js
jsc /t:library /out:BitFieldClass.dll bitFieldClass.js
Of course, if you wanted to do multiple files, you'd have to parameterize things a bit, but hopefully this is enough to demonstrate the idea.