From: Rob Ram Date: 2008-12-26T17:48:56+09:00 Subject: Re: Calling Ruby from Delphi Huw Collingbourne wrote: > You can connect Delphi Prism (Chrome/Oxgene) or C# or some other .NET > language with the Ruby interpreter using our free component, The Ruby > Connector. I haven't used Delphi 2009 (does that still have a .NET > version?) so can't comment specifically on that. The Ruby Connector > comes with a comprehensive manual and lots of sample code... > > http://www.sapphiresteel.com/SapphireSteel-Downloads > > best wishes > Huw Collingbourne > > SapphireSteel Software > http://www.sapphiresteel.com Thank you for your reply. I was successful calling Ruby from Delphi 2009. I used the Delphi API found at: http://sourcepole.ch/2006/9/1/embedding-ruby-in-kylix-delphi . This was originally written for Delphi 2006. However it will work with Delphi 2009 with minor modifications. Delphi 2009 now supports Unicode strings and user code strings must be re-cast to ansiString/pAnsiString/ansiChar/pAnsiChar to be compatible with Ruby strings. Delphi 2009 is intended for native Windows development. There are other versions of Delphi available for .net support. The source code, “rubycomp-0.8-src.tar.gz”, provides a Delphi component for easy evaluation. In my case however, I did not want to re-direct the IO and removed the Ruby component. Otherwise, Ruby access is through msvcrt-ruby18.dll. The source code provides Delphi files to access the Ruby DLL. It’s basically ruby.h and other c++ files re-written for Delphi. To call Ruby functions from Delphi (in simplified terms): 1. First initialize Ruby. 2. Then use rb_require function to load the Ruby file. 3. Calling the “rb_eval_string” can easily access any function within the Ruby file. For example: rv := rb_eval_string(‘myFunction(a,b,c)’); // From the prior example. 4. Finally evaluate rv using: rtn := dl_Variant(rv); // where rtn is a variant array. // multi-results from the prior example. rv1 := rtn[0]; rv2 := rtn[1]; rv3 := rtn[2]; The dl_Variant function is found in uConv.pas (extracted from rubycomp-0.8-src.tar.gz). There may be better methods to call a Ruby function from Delphi, but this does seem to work efficiently. -- Posted via http://www.ruby-forum.com/.