I was going to write something about how I got nested types working last night, and some cool Ruby features that I discovered to make it work (remind me later – it is a very cool story), but there’s something much more exciting to report:
I’ve built my first trivial Windows Forms 2.0 Application using RubyCLR!
Yes, it is the “Hello, World” Windows Forms data binding application, but it represents a major step forward in the maturity of RubyCLR. Lots of features had to be added to the product to make this work, and that’s what’s been driving most of my development effort recently; I’m worrying less about the edge cases for now, and focusing on implementing the most important core features to make it usable.
Now, this application is not intended to represent anything about how one would actually write Windows Forms applications using Ruby – this application is very un-Ruby-esque. I can imagine lots of ways to improve how it’s implemented, and I’m going to spend a few days building an app to see what kinds of idioms I can discover along the way (provided the bridge is stable enough to actually build that app).
Here’s the code:
require 'rubyclr'
RubyClr::reference 'System.Data'
RubyClr::reference 'System.Drawing'
RubyClr::reference 'System.Windows.Forms'
include System
include System::Data
include System::Data::SqlClient
include System::Drawing
include System::Windows::Forms
class MainForm
attr_reader :form, :grid
CS = 'server=.\SQLEXPRESS;database=adventureworks;integrated security=sspi'
SQL = 'select * from humanresources.employee'
def create_form(grid)
form = Form.new
form.AutoScaleMode = AutoScaleMode::Font
form.ClientSize = Size.new(292, 266)
form.Controls.Add(grid)
form.Load do |sender, args|
adapter = SqlDataAdapter.new(SQL, CS)
ds = DataSet.new
adapter.Fill(ds, 'Employee')
grid.DataSource = ds
grid.DataMember = 'Employee'
end
form
end
def create_gridview
grid = DataGridView.new
grid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode::AutoSize
grid.Dock = DockStyle::Fill
grid.Location = Point.new(0, 0)
grid.Size = Size.new(292, 266)
grid.TabIndex = 0
grid
end
def initialize
@grid = create_gridview
@form = create_form(@grid)
end
end
Application.EnableVisualStyles
Application.SetCompatibleTextRenderingDefault false
main = MainForm.new
Application.Run(main.form)

2 archived reader comments
Justin (2006/02/16)
Looks really cool! I especially like the block passed to the delegate. Presumably we’ll also be able to give those a proc?
John Lam (2006/02/16)
There’s no support for Method objects right now. Part of the problem revolves around blocks acting as closures (which is very useful); since I’m using delegation / containment as the model, I need the right scope for the block. Right now, using blocks feels more natural - although I can certainly see adding support for Method objects in the future.