Friday, December 18, 2009

How do I OLE?

I saw a perfect example of using OLE objects in Magik session In Alferd's sworldwatch for regular expression validator (
But finding the ole component is not a simple task, if we are looking for something new. It takes good amount of time for searching the ole components like vbscript.regexp.

So we need a tool which lists all the available ole components.

Visual studio comes with Ole Viewer Tool shows list of COM objects and its properties. Which will make life easier to find the objects, What if we don’t have ..??
Here is the solution (;en-us;122244)

Download ole2view this application lists all the available COM components in WINDOWS.

Wednesday, December 2, 2009

SW Media Player

sw media player is a simple media player(only audio)
This again works using ole_automation by geting handle on windows media player activex component. ( so becomes platform dependent )

I added lot of actions but couldn't implement all...
it has the basic functionality like play, stop, ff, fr, pause.
Time seek will show the current position of the audio file but it doesn't update if we drag it.

It will work from emacs with three lines of code

.player << ole_client.create_object("wmplayer.ocx")
.control << .player.controls
.player.url << "C:\WINDOWS\Media\Windows XP Logon Sound.wav"

Serves as online radio if URL is replaced with some live radio for eg:

Download sw mdia player form here

control.stop will stop playing audio file. similarly play, pause etc are available on control class.

I tried to add play list to the tree item with add and remove functionality but finally did nothing

If found any new ideas please add to comments

Sunday, November 8, 2009

Add behavior to Tree Item

I am a big fan of tree_item and Tree_item is one of the most powerful controls provided by magik language. I can't imagine many Office applications with out a tree_item (very few without a tree_item)

From few days I am trying to develop a Yahoo messenger kind of application in magik using tcp/ip communication.

One of my requirements is to show details on mouse over on the list available. But I think the tree_item doesn’t have mouse over functionality added (at least in my scope of knowledge). I spend couple of minutes to provide a customized behavior like mouse over action to tree_item

Here is the way to add the mouse over behavior to tree_item:
(These changes are to tree_agent.magik didnt tried subclassing it)
1. add a pseudo slot say mouse_over_func and define the slot access to writeable
2. add the mouse_over_func to exported_notifiers and notifier_for_action
3. initilise the handler in init() of agent as below
.mouse_over_func <<, :default_mouse_over|()|)
4. enable the events for the tree in window.enable_event(:move)
5. in default_handle_event(), notify to the desired method as below
_if l_id _is :move

_return _self.notify(:mouse_over_func, l_row, l_row_index, p_event)

_private _method tree_agent.mouse_over_func << p_new

.mouse_over_func <<, :default_mouse_over|()|)
>> .mouse_over_func

method tree_agent.default_mouse_over(p_tree, l_row_index, p_event)
#write(p_tree, l_row_index, p_event)

_local l_sel_column << _self.column_at(p_event.x)
#do some thing
_if l_sel_column _is _unset



I just tried this code and I haven’t tested fully… but this is working. I added my custom method in the class as we do for select notifier or double click notifier.. it is working with few tracebacks.. Those are to be handled in tree_agent. default_mouse_over()

Friday, November 6, 2009


“SW Narrator” is a simple application which reads any action performed on smallworld application. it is as simple as Narrator provided by default in windows operating system. This is developed in magik by using SAPI.

Interestingly heart of the application is only 2 lines

MagikSF> v << ole_client.create_object("sapi.spvoice")

MagikSF> v.Speak("smallworld")

Sw narrator gets every action performed by application by add_filter_event to :interaction_mode_event. This will give handle to action and there it retrieves the UI value.

Code written in click_monitor in development tool serves the purpose.

Looking for some online drive to upload the module… I will update once I shared the module.

Thursday, November 5, 2009

Draw 3D pie diagram in Excel from magik

This piece of code will help to draw a 3d pie diagram in excel sheet from magik..


e << OLE_Client.Create_Object("Excel.Application")
w << e.Workbooks()

s << e.Sheets("Sheet1")
s.Name << "bhimu"
_for i _over range (1,10)
Cell << S.Range ("A"+i.print_string)
Cell.Value << i
Cell.Release_Object ()
Cell << S.Range ("B"+i.print_string)
Cell.Value << "=A"+i.print_string+"*"+"A"+i.print_string
Cell.Release_Object ()

c << e.charts.add
c.ChartType << :|xl3DPieExploded|
e.ActiveChart.Location(:|xlLocationAsObject|, "bhimu")
e.Visible << _True


if location is not specified, then the chart is added to a new sheet.


I started this blog from the inspiration I gained from sworldwatch, thanks to Alfred Sawatzky.

I have almost 3 years of experience in magik. I tried different applications in magik. Still i am in learning phase, but liked to post some intresing stuff I found while learing.

I am starting my first post with GIS/Geospatial Industry Worldwide and their positions. Smallworld is in 3rd position with around 8% GIS market share and around 24% Utilities share. (data collected from daratech)