Thursday, July 07, 2005

New Job!

It's time for a new job! I'm now at Flovate Technologies, as Chief Executive Officer, India. That's a fancy title all right. But wait till you hear about my computer! (This is geeky)

I get a Dual Xeon 3 Ghz monster, with a 22" main and a 15" secondary monitor. There's 1 GB ram and SCSI RAID disks totalling 140 Gigs of Bytes. And a 128 MB ATI Card, and three mice running around in wheels. Awesome stuff. I just get lost in the incredible real estate on the screen. My 15.4" Dell latitude is like a crowded alley in comparison.

I get to manage the team in India and co-ordinate with the folks in the UK, where I must say there are some incredibly talented developers! I just went through a couple of frameworks and man, this stuff is really impressive. I can't reveal the juicy details, but let me just say that if there's a Workflow map in the future, we're going to be on it.

Non geeky stuff: I'm learning the ropes on a different kind of management. It's so tempting to get into code, but it's simply better not to touch it until you really understand the situation. I used to think the code was king, that you could figure out anything just looking at the source code : Yes, at this point I can probably identify a ton of patterns by looking deep enough. But does that really matter? What you really need to understand, right off the top, is what the product or project is about. What kind of users use it, what the business proposition is. Imagine you're the customer, and ask stupid questions (the former sometimes implies the latter). Only then get into the code!

I also need to understand that every developer will take short cuts, even the best of 'em. To refactor is one thing. To identify and create an environment that will support and encourage refactoring is quite another. And then there's the whole scheduling, project management etc. issue - I think I'm going to become a PHB.

Anyhow, what's important is this: I can have THREE rows of icons on the status bar and still have enough on the screen to eat dinner out of. Ha!

No seriously, this is going to be one helluva challenge. I'm quite looking forward to it! My next few posts might involve lesser technology. Or more. I don't know. Interesting times, indeed.

Friday, July 01, 2005

Delphi problem with uploading compressed streams

In my Advanced Web Services article, I had demonstrated how you could do Datapacket compression by compressing the ENTIRE packet before it was sent from the server, and decompressing it at the client end. (Applies to encryption also)

Now I'd said you could do this the other way around too : compressing packets before sending on the client end, and expanding them at the server, using the BeforeRequest event of THTTPRio. This doesn't work: Firstly there is a bug in D7 SOAP, that ignores the var parameter in the BeforeRequest handler. Look here for a fix I've mentioned.

A bigger problem is this: The BeforeExecute event is declared like this:

TBeforeExecuteEvent =
procedure( const MethodName: string;
var SOAPRequest: InvString) of object;


Now if you do some kind of compression or encryption, you might not like to deal with the WideString parameter. The process might introduce some NULL (0) characters in the character array, which will then be truncated by Delphi (which assumes a string ends on a NULL character).

Fortunately, the source is king. Here's a few steps:

  1. Write a descendant component from THttpRio (call it THTTPRioEnh)

  2. Declare a type like so:

    TBeforeExecuteStreamEvent =
    procedure(const MethodName: string;
    Request: TStream) of object;


  3. In the THTTPRioEnh class, declare a published variable of type:


    property OnBeforeExecuteStream: TBeforeExecuteStreamEvent
    read FOnBeforeExecuteStream
    write FOnBeforeExecuteStream;


    Hit Ctrl+Shift+C. The private variable should get declared
    automatically.

  4. override the DoBeforeExecute procedure and in it put:


    procedure DoBeforeExecute(const MethodName: string;
    Request: TStream);
    begin
    inherited DoBeforeExecute(MethodName, Request);

    if Assigned( FOnBeforeExecuteStream ) then
    FOnBeforeExecuteStream( MethodName, Request );
    end;


  5. Then register the component using a Register procedure, put it in a package, compile and install.

You can then drop a THTTPRioEnh component on your form, and assign a handler to OnBeforeExecuteStream of this component.

I am lazy, so I did all this in Rio.Pas and instead of creating a handler in the IDE I set this up in code instead, something like:

HTTPRio1.OnBeforeExecuteStream := BeforeExecuteStream;


Where I do the modifications to the request stream.