Monday, July 26, 2004

Open Source Myths

A post in our local Linux user group pointed me to an article about Common Open Source Myths. I especially like the All Software should be Free paragraph; Software should never be treated as something that must be free. Even as in beer. Because at a very macro level, the small company is going to have problems - imagine a garage company that makes and sells something. If they need accounting software, it's free (GREAT!) but now if they have a problem, they have choices of:

a) Contact a programmer who wrote the software, which is open source, so he's funded by his full time job in organization X that makes microprocessor chips. So he doesn't have time to fix or address the problem immediately, or

b) Find a "support" company that will support this famous open source software, but they're either too expensive or don't have any good programmers who can fix the software using the source code. Because the best programmers are at company X at makes microprocessor chips.

My point: The best programmers will leave the industry if there's not enough money to be made writing software.

Extrapolate further: as support becomes the only money making opportunity, countries like India and China, who have vast resources of programmers, will be able to provide support at much cheaper rates. (No, I don't believe providing "support" is a wonderful thing to do, even if it provides revenue for my country. We'll always stay at the bottom of the value chain) And if the entire business model depends on support - why would anyone ever want to fully document software? Or even fix things that they see as potential problems, but aren't noticed by customers yet? (Hey, we can bill them for it when they find out :) )

I like open source software - I use many tools that are open source. Our internal company rule disallows the use of GPL based components in any of the work we do, but we do use MPL and other free licence based components. But I think closed and open source software should co-exist, as competition.

There's tons of free source code dished out in newsgroups, source code (even from Microsoft) and websites such as CodeProject. Anyone can use this source code today: I just hope such code doesn't become inaccessbile to us closed source application authors!

Thursday, July 22, 2004

India Delphi User Group (INDUG)

We started INDUG a few years back, and boy has it grown! 776 members and counting...what's surprising is that in the last few days the activity has started to heat up. Turns out there were 48 members in the last two months!

Delphi is growing up, at least in India. I don't know what the reason is, but it seems like a lot of companies have started to look at Delphi seriously - I just heard of an appliance company that's using Delphi! And the ads in the Employment sections seem to have a lot more Delphi-count nowadays. I don't know if this is absolutely correct, but it looks like for Win32 folks that aren't into C++, Delphi's simply the best option in the market. Microsoft's hardselling .NET but everyone knows that Win32 isn't going anywhere soon - and .NET isn't going to be ubiquitous anytime soon either.

Tuesday, July 20, 2004

MSBuild - the build tool of the future?

I just found out that Microsoft is planning to ship MSBuild as part of the CLR. Now I can't find the link to MSBuild itself - anyone know? - but I found the blog of the MSBuild dev team. You can also download the bits that will work with version 1.2 and 2.0.

Very interesting tool, this. You can schedule your builds, co-ordinate check outs/check ins, zip/unzip files, deploy to remote directories etc., all using a single XML. Something like FinalBuilder, except this is now going to be part of the CLR. And I have no clue what the GUI will look like, but I do like FinalBuilder's GUI.

If I find the time, I'm going to write a Delphi compile action for MSBuild. If someone beats me to it, let me know :).

Friday, July 16, 2004

Set Next Statement in Delphi?

I am a huge fan of Matt Pietrek. I also just found his home page. And guess what, he even worked for Borland!!! Oh and you should read his material - Under the Hood on MSDN, the Windows Internals, System Programming Secrets and Undocumented Windows books, and this (the last one isnt his, but hey it deserves a mention).

Okay, so in his Blog, Matt mentions a "Set Next Statement" - something in VS that allows you to actually move the next instruction executed to a new position. This isn't exclusive to VS, you can do it in Delphi too, it's just not documented well enough. Here's how you do this:

Let's say you have this kick-ass piece of code:

procedure TForm1.Button1Click(Sender: TObject);
begin
DoSomethingStupid;

ShowMessage('Done');
end;

procedure TForm1.DoSomethingStupid;
begin
while true do ;
end;


You should never be able to debug this down to the "ShowMessage('Done');" statement, because of the wonderful "while true do ; " code. Now I've faced this problem many-a-times; I just want to get out the DoSomethingStupid function, and move on to the next piece of code which I've got to test. (Recompiling is easy in Delphi, you say. Ha. Not if relaunching of the app involves a login, navigation, entering some specific data and then debugging.)

Set a breakpoint in the "while true do;" line. When the program breaks there, hit Ctrl+Alt+C (or View|Debug Windows|CPU). The windows looks like this:



Right click on the next line (with the ret instruction) and select New EIP.




EIP is the (Extended) Instruction Pointer, which is what makes you a pointy haired boss (PHB). No, that's something else. Anyways.

What happens next is that your ShowMessage call runs! so you're out of the infinite loop, without having to recompile. This is very helpful when you've made an obvious blunder (like in saving a file, you've given an invalid path) but that blunder doesn't affect anything else like parameters, stack etc. (And don't try doing this to get out of a try/except/finally statement - won't work most of the time)

The CPU window is your friend. There are tons more tricks you can use - Danny had an amazing session ("Reading Tea Leaves") in a BorCon long back that led me on to this, but there's not much else I've remembered...

Tuesday, July 13, 2004

WFML : A DFM equivalent for .NET?

Check out http://windowsforms.net/articles/wfml.aspx. This is a component that can use XML markup to "design" forms - so you can have your form design separate from your code! Very much like Delphi DFMs - and the event model also expects handlers inside of the .CS class. No designer for it, of course - and probably no support in Longhorn either - XAML does this in Longhorn anyhow.

But you know what, this does one thing that I've always wanted in Delphi - allows me to put comment in the form design code - i.e. comment out a component easily. Even in the .NET IDEs, you can't really muck about with the "InitializeComponent()" code - they don't like it too much, for reasons I can't understand. (If you're parsing, parse it right, dammit. So what if I chose to comment something out?)

But the app is *slow*. No, this isn't just .NET - XML parsing in general is slow, and then all the stuff like dynamically creating stuff is slower.

Sunday, July 11, 2004

PInvoke - Win32 declarations again

I found a GotDotNet Sample that looks like it has some of the Windows.H declarations. No #defines converted, though.

So why am I harping about all this PInvoke stuff? i just don't believe that .NET's going to be the only platform for years to come, and there's tons of things in Win32 that are plain ignored in the FCL. So, we'll need PInvoke for a while - and it's better to have a ready set of translations so you can use what you're going to need.

Thursday, July 08, 2004

ListView - Groups?

I was wondering how the groups and "tiles" worked in XP. For groups we have some code here. Useful, definitely - still need to figure out the "tile" thing.

Tracker. Free.

I've always been a fan of bug tracking apps - have at least 10 of them on my machine! But this one just plain blew me away. Check out Tracker at:

http://windowsforms.net/articles/writingntierapps.aspx
Download Tracker Here

Pretty nifty, or at least the screen shots say so. I took some time off, installed it - and found it does NOT like MSDE...(not a named instance anyhow). So after figuring that out, I uploaded it to a SQL server base instance here, and then created the database, and voila! I had a winner. This app is just COOL. I haven't used it much but it makes me want to - I'll see how it goes and post a progress message next week or so.

And this is free. With Source. Non GPL'ed. Isn't that something?

Also, check out the ASP.NET starter kits at http://www.asp.net/Default.aspx?tabindex=9&tabid=47

Unloading an ISAPI dll from IIS

I got this snippet from the borland.public.delphi.internet.isapi-webbroker newsgroup - a simple way to unload an ISAPI dll programmatically:


var
WSite, WServer, WRoot: Variant;
begin
WSite := CreateOleObject('IISNamespace');
WSite := WSite.GetObject('IIsWebService',
'localhost/w3svc');
WServer := WSite.GetObject('IIsWebServer', '1');
WRoot := WServer.GetObject('IIsWebVirtualDir',
'Root');
wserver.stop;
wroot.appunload;
wserver.start;
end;


This works on XP - I didn't even know you could create an OLE object with "IISNamespace". But you can. Anyhow, in the WSite.GetObject call you see a "1" - if you're wondering what that is, it's the number given to a web site by IIS. You can get the numbers of all your websites through Adsi - import the Ads type library and use the code from my ADSI paper like this:


var serv : IADSContainer;
e : IEnumVARIANT;
varArr : OleVariant;
lNumElements : ULong;
obj : IADs;
hr : integer;
begin
// list web sites
AdsGetObject('IIS://localhost/w3svc',IAdsContainer, serv) ;

hr := ADsBuildEnumerator(serv,e);
while(Succeeded(Hr)) do
begin
hr := ADsEnumerateNext(e,1,
varArr ,lNumElements);

if (lNumElements=0) then
break;

IDispatch(varArr).QueryInterface(IADs, obj);
if obj<>nil then
begin
if obj.Class_ = 'IIsWebServer' then
// obj.Name contains the "number" you need.
end;
obj := nil;
varArr := NULL;
end;
//don't call ADsFreeEnumerator(e);
//since e will be released by Delphi
...
end;


You can use ADSI to do a ton of things. I've been planning to finish up a set of ADSI components for Delphi - never had the time though. I don't even know if there'll be enough people who need it - but I do get something like 10-20 mails a month on my paper. If the market's big enough, I'd like to make it commercial - which gives me time to work on it. Otherwise it goes as "free" stuff, but no time allocated to finish it. Tough call.