Tuesday, March 10, 2009

Delphi Performance Tip

Here's a small little Delphi performance tip that I'm not sure many people are aware of. Putting the $EXTERNALSYM after the symbol has better compiler performance than placing it before the symbol. The reason for this is pretty simple. When the compiler encounters a $EXTERNALSYM it looks for the symbol. If the symbol isn't found then it must be stored and dealt with later. If the symbol is found it is used immediately.

Here's a small example:


const
MAPVK_VK_TO_VSC = 0;
{$EXTERNALSYM MAPVK_VK_TO_VSC}
MAPVK_VSC_TO_VK = 1;
{$EXTERNALSYM MAPVK_VSC_TO_VK}
MAPVK_VK_TO_CHAR = 2;
{$EXTERNALSYM MAPVK_VK_TO_CHAR}
MAPVK_VSC_TO_VK_EX = 3;
{$EXTERNALSYM MAPVK_VSC_TO_VK_EX}
MAPVK_VK_TO_VSC_EX = 4;
{$EXTERNALSYM MAPVK_VK_TO_VSC_EX}

Tuesday, March 3, 2009

Happy Square Root Day!

I hope everyone is having a happy Square Root Day.

I have a photograph of a square root in Costa Rica but my photo library isn't available at the moment.

Friday, February 20, 2009

Delphi Live!




I just opened up a poll (you can view it on the sidebar), to see how many readers of this blog will be attending Delphi Live! I'll be there at least one day giving talks and milling around.

Thursday, February 19, 2009

New Embarcadero Website for All-Access



All-Access was launched yesterday and the Embarcadero website got a nice looking face lift. I feel like we are a whole lot hipper than before. It looks like we are a bunch of rock stars! Or we are going to start selling iPods.

The halls are buzzing with excitement with All-Access. This really is the tool chest for developers. It won't appeal to everyone but the people it does appeal to will really like it.

Saturday, February 14, 2009

Happy Valentines Day



Happy Valentines Day everyone. Oh, and Happy 14th Birthday Delphi!

Tuesday, February 3, 2009

Windows 7 on Mac

I've been running Windows 7 under VMWare Fusion on my Mac Pro without a problem for a few days now. VMWare doesn't give you the option for Windows 7, but choosing Vista from the install wizard worked just fine. I do run into one issue. When running Windows 7 and I eject the DVD-ROM drive with the eject button on the keyboard, the same button should suck the drive tray back in but it doesn't.

I think Windows 7 will be what Windows 95 was to Windows 3.1. The rumor mill has it that Windows 7 will ship before the August timeout date of the public beta. The beta is so rock solid it wouldn't surprise me.

If anyone is having any Windows 7 issues with Delphi 2009 or C++Builder 2009 please post a comment. I've been running without a hitch.

Friday, January 30, 2009

Delphi Object Inspector Tip of the Day

Did you know you can incremental search in the Object Inspector? Focus any item in the object inspector with your mouse or F11, press Tab the cursor will be brought to the name side of the object inspector, start typing, then press Tab again and the cursor will be back on the value side of the Object Inspector. Yeah, it probably should be more obvious.

Working with IStream in Delphi

At some point you might have to work with IStream. They are never fun to work with. Especially since you can't insert into a stream without overwriting. But that's streams.

I like to use the VCL wrappers, TOleStream and TStreamAdapter, and then use TMemoryStream. Use TOleStream to wrapping up an IStream making it look like a TStream and then use TIMemoryStream to make the TMemoryStream look like an IStream again.

Let's say for some reason we get a UTF-8 stream that needs to be saved as a file but it has no BOM. Here's a small example of how to add a BOM to the stream using Delphi:


uses ActiveX, AxCtrls, Classes;

function AddBomToStream(const Stream: IStream): IStream;
var
Bom: TBytes;
OleStream: TOleStream;
MemoryStream: TMemoryStream;
Temp: Largeint;
begin
if Stream <> nil then
begin
MemoryStream := TMemoryStream.Create;
Bom := TEncoding.UTF8.GetPreamble;
MemoryStream.Write(Bom[0], Length(Bom));
Stream.Seek(0, STREAM_SEEK_SET, Temp);
OleStream := TOleStream.Create(Stream);

try
MemoryStream.CopyFrom(OleStream, OleStream.Size);
Result := TStreamAdapter.Create(MemoryStream, soOwned) as IStream;
finally
OleStream.Free;
end;
end;
end;

Monday, January 26, 2009

1,474 Megapixel Photo

If the caption of this post interest you then click on to see how David Bergman How Made a 1,474-Megapixel Photo During President Obama's Inaugural Address. It's almost like being there.

Friday, January 23, 2009

Windows 7 Taskbar

The Taskbar in Windows 7 is as revolutionary as the original Taskbar was in Windows 95. Rather than reiterating how it works, ars technica has a good article describing it in detail and in comparing it to the Mac Dock. Although ars claims they are nothing alike, I have to disagree, Microsoft definitely got some ideas from the Dock. Although they may have arrived at the same UI all by themselves if the Mac Dock hadn't existed, the influence is undeniable.

Thursday, January 15, 2009

Silly Windows 7 Mouse Shortcut

I just found out you can shake a window with the mouse and all other windows are minimized. If you shake it again all the other windows come back.

Nice Windows 7 Keyboard Shortcut

Yesterday I discovered on Windows 7 that holding down the windows key and any of the 4 arrow keys will resize the active window between full screen, windowed, minimized and aligned to the left or right of the monitor.