SQLite and Delphi 2009

I created a simple Delphi wrapper for SQLite, the popular open source database library. I’ve just updated it to work with Delphi 2009 – I’m not happy with what I’ve done, because I’ve changed a bunch of declarations from PChar to PAnsiChar and from String to AnsiString, just to get it working quickly. SQLite is fine for Unicode, so the next step is to revise it properly to support Unicode … when I or someone else has time.

It was interesting to do some work with Delphi 2009. It has the old problem: out of date documentation. Here’s what it says about PChar, in the entry on pointer types:

The fundamental types PAnsiChar and PWideChar represent pointers to AnsiChar and WideChar values, respectively. The generic PChar represents a pointer to a Char (that is, in its current implementation, to an AnsiChar).

Further, if you have the following code:

var
strTest: PChar;
begin
strTest := StrAlloc(6);
strcopy(strTest,’Hello’);
strdispose(strTest);
end;

and hover the mouse over strTest in the editor, the pop-up tip says:

strTest – System.PAnsiChar

However, this is wrong. In Delphi 2009, a generic PChar is a PWideChar. Here’s the code in SysUtils for StrAlloc:

function StrAlloc(Size: Cardinal): PChar;
begin
{$IFDEF UNICODE}
  Result := WideStrAlloc(Size);
{$ELSE}
  Result := AnsiStrAlloc(Size);
{$ENDIF}
end;

UNICODE is defined in Delphi 2009, so StrAlloc returns a PWideChar.

Technorati tags: , ,

HP laptop go-slow caused by power supply

Wasted some time recently looking at an HP Compaq NX7300 laptop, with Vista, that was running very slow.

No, not just normal Vista sluggishness. Really slow, as in you click the Start menu, wait a bit, and eventually it opens.

Temporarily disabled everything we could think of using msconfig (System Configuration Tool), still slow.

Checked the event log for disk errors, nothing wrong.

All very tedious as any actions took much longer than usual.

Found someone with the same problem on HP’s support forum here – but as so often with the Web, no solution is reported – though the guy does say, “can I assume that the cooling / cpu / power is defective”?

Called HP, and the guy diagnosed a faulty hard drive, though I was sceptical since his argument was that the self-test completed more quickly than expected, though it did not report any errors.

While scratching my head over this, I recalled that this laptop has what HP calls a “Smart AC Adapter”, which has an annoying proprietary connector featuring an additional central pin. According to this thread it actually supplies two separate power lines. The discussion includes this remark:

I tried to substitute the original HP AC adapter, with a general purpose AC adapter, applying a resistor divider between input cylinder- central pin-output cylinder, in order to get the second voltage.  But the laptop did not function normally: it was very slow

and someone adds

The slow function of the system with the alternative power source may be due to the system’s picking up a low voltage on the ‘monitoring’ pin.  This would indicate a low battery or weak charger and the system responded by cutting back on CPU/mainboard frequency to conserve power.

Could this be a clue? We started the laptop on battery power; suddenly it worked fine again. Plugged in the power cable, it slowed down. Removed the power cable, it speeded up again. Bingo.

New power supply is on order. It occurs to me that this could still be a problem with some internal connection, but I’ll be surprised if the new mains adapter does not fix it. Just occasionally the reason for a slow computer is nothing to do with Windows.

Technorati tags: , , , , ,

Losing your religion: how to survive the tech downturn

I posted a piece on itjoblog summarizing and reflecting on Tim Bray’s tips for surviving the tech downturn, if you are a software developer.

Yesterday was another grim one on the world’s stock markets; this morning the London stock exchange is down another 3.74% at the time of writing. I’m not seeing much reason to doubt Bray’s pessimism. Still, there’s always tomorrow.

Technorati tags: ,

Flash Marches On: We are upgrading the Web, says Adobe

Adobe has just released version 10 of the Flash runtime, the piece which is now at the heart of many of the company’s other products. It is extraordinary to recall that there was no Flash in Adobe until 2005 and the acquisition of Macromedia. Flash is now Adobe’s platform, and much of the output from other products like Photoshop or Creative Suite ends up as Flash content. Before 2005 you could argue that PDF was Adobe’s platform; it remains important, but now we are seeing Flash encroach on that territory with new typography and text-handling features forming one of the key advances in Flash 10. Adobe’s online word processor, Buzzword, is based on Flash and not PDF; whereas in the old world I might send you a link to a PDF, or attach it to an email, now I might send a link to a Buzzword document. I’d perhaps more likely send a link to a Google doc, of course, but you can see where Adobe is going with this.

The thing that Adobe talks about most in Flash 10 is Pixel Bender, formerly code-named Hydra, a graphics programming language that enables custom filters, effects and blend modes. Translation: fancy video effects. There is also an improved drawing API, 3D effects, more use of hardware acceleration, and new sound APIs. Game developers will love it, so will those designing Flash ads.

The other thing Adobe emphasises is reach. Flash is on 800M devices, we were told at the online press briefing yesterday, with 1 billion projected for 2009, and delivers 80% of the web’s video. I asked how many of the 800M were Flash 9 or better; I did not get an answer to the exact question; Adobe’s reply talked only about web-connected PCs. There is more of a problem with devices; Flash on my Smartphone (Windows Mobile 6) is a terrible experience.

It can’t be a coincidence that Microsoft has delivered the final Silverlight 2.0 runtime at almost the same time as Flash 10 appears. A few observations on Flash vs Silverlight. Microsoft is the underdog here, in respect of reach and of course adoption, though that’s hardly a surprise considering Silverlight is new and Flash has been around for years. Still, why would a Flash developer would migrate towards Silverlight? I’m not seeing much sign of that.

Despite their obvious similarities, Flash and Silverlight are being presented in different ways. Adobe puts the emphasis on multimedia capabilities, while Microsoft highlights application capabilities. In fact, I think of Flash as a multimedia runtime with application capabilities, whereas I think of Silverlight as an application runtime with multimedia capabilities. Adobe treats the application aspect as a separate topic, to do with Flex and Flex Builder, whereas it is central to Microsoft’s Silverlight story. Both companies play to their strengths; things look better for Microsoft if you talk about Visual Studio versus Flex Builder, rather than Silverlight versus Flash. Equally, if you position CS4 versus the Expression suite, it looks pretty bad.

The Flash runtime is around 1.8MB, whereas Silverlight is around 4.5MB. Personally I doubt that is of much significance, except for users on dial-up connections. They are both small enough.

Kudos to Adobe for delivering Flash 10 for Linux at the same time as for other platforms. I successfully installed this on my Ubuntu system, though the process is not as smooth as on Windows. This contrasts with Microsoft’s uncertain Linux support with Silverlight/Moonlight.

Finally, a comment from the spokesperson the press briefing has stayed in my mind. “We are able to upgrade the Web very quickly”, he said. Does the Web belong to Adobe, that it can upgrade it?