Friday, April 25, 2008

Delphi put by ref properties

In Delphi 6 and earlier there was a an unintended compiler feature, put by ref properties. It allowed properties to be passed by references. Here is an example:


function GetCount: Integer;
procedure SetCount(var Value: Integer);

property Count: Integer read GetCount write SetCount;

It was decided that the setter property by reference wasn't safe so starting with Delphi 7 this became a compiler error. But this is a requirement for COM so the compiler option {$VARPROPSETTER ON} was introduced to enable the put by ref behavior. At the top of each _TLB.pas file generated you will see this compiler directive.

Wednesday, April 23, 2008

Upgraded to Leopard

Everything I needed to upgrade to Leopard now supports Leopard. So I bought a new 1TB Wester Digital Caviar hard drive and installed it in minutes in my MacPro. It really was the easiest hard drive install I've ever done. Leopard was just as simple. Put the DVD in the drive, hold down the C key to boot from the optical drive and then run the install. How the heck are you supposed to know to hold down the C key unless you read the directions? Typical Apple, make the most common things easy and the slightly harder things buried. Last I ran the user migration assistant which moved everything over to the new hard drive. Easiest new install of an OS I've ever experienced. And nearly everything is migrated over. I've never had that experience with a new install of Windows.

I ran into a few oddities:

- Safari had some funniness with the bookmark bar where some of my links showed up in a couple locations.
- My Wacom tablet driver didn't have sufficient privileges to run.
- The default output for the sound was changed to the internal speaker not the line out to my desk speakers.

But that's it so far. I'm sure something else will crop up.

The first strange thing I noticed is quick viewing items on the desktop opens the quick view window on the secondary monitor. I only turn on my second monitor when I'm reviewing a large photo-shoot so this is kind of a problem.

This is the first OS upgrade I've ever had where the new OS was faster than the previous one on the same hardware. Okay, I got a new hard drive, but I don't think that is coming into play here. Things are just snappier.

I still have to test out all my applications. I'm running the first update now so I'll know more tomorrow.

Tuesday, April 22, 2008

BusySync for Mac

For a while now I've been trying to find a good way to keep the Missus' and my calendar's in sync. One of my fellow CodeGear Mac heads mentioned BusySync so I gave the trial a whirl. It just worked out of the box as easy as could be and kept our Macs iCals in sync. The only problem left was knowing my schedule when I'm not at home. Lots of people suggested getting an iPhone and that'd be great if I weren't a Verizon customer and switching over to AT&T wouldn't cost me over $50 per month more than what I pay now. Then I'd still have to carry it and I'm at work most of the time when I need to know my schedule anyway. Then BusySync just got cooler and released BusySync 2.0 that syncs with Google Calendar. Hot diggity dog, it works swimmingly! They also have a discount going on right now. If you use a Mac and need to sync your calendars on two or more Macs then give it a try.

Thursday, April 17, 2008

Delphi Tips and Tricks: Model View

I've been using the model view quite a bit lately and it's a little uh, well, ugly and difficult to navigate. There is an option, although not widely known and a bit burried, that makes the model view a whole lot more usable. Although this option isn't "preferred by modelers" it sure does help us coders use it.

To enable the simplified Model View go to Tools | Options, scroll down the tree to Together | Default | Diagram | Model View and change View type from Model-centric to Simplified.



Updated: Here are two screen captures from the Model View before and after toggling the option. This is after creating a new Delphi VCL Application. Can you figure out which one is which?



Tuesday, April 15, 2008

Delphi Tips and Tricks: Import Component Wizard



The Import Component Wizard supports copy (CTRL + C). If I press CTRL + C on the dialog above I get "Active Setup Control Library, Version 1.0, C:\WINDOWS\SysWOW64\asctrls.ocx" in my clipboard buffer. Kinda handy.

Friday, April 11, 2008

Writing a Delphi Menu Item Plugin

Trying to figure out the Delphi Open Tools API can be a daunting task. Here is a bit of code to get a menu item into the Delphi IDE's main menu. Please note that I didn't test this code and you will want to reorganize it a bit.


unit ComStdReg;

interface

uses Menus, ActnList;

type
TMyMenus = class
private
FMenuItem: TMenuItem;
FMenuAction: TAction;

procedure DoExecute(Sender: TObject);
procedure DoUpdate(Sender: TObject);
public
constructor Create;
destructor Destroy; override;
end;

implementation

uses ToolsAPI;

constructor TMyMenus.Create;
var
MenuService: INTAServices;
begin
MenuService := BorlandIDEServices as INTAServices;

if MenuService <> nil then
begin
MenuItem := TMenuItem.Create(nil);
MenuAction := TAction.Create(nil);
MenuItem.Action := MenuAction;
MenuItem.Name := 'MyMenuItem';
MenuActiond.Caption := 'My Menu Item';
MenuAction.OnExecute := DoExecute;
MenuAction.OnUpdate := DoUpdate;
MenuAction.Enabled := False;

// Only set this if you want to allow F1 when the mouse if over the menu item.
MenuAction.HelpContext := 0;

// Tell the menu service which item to place your menu item after. This will
// place your menu item after Component | Installed Packages.

MenuService.AddActionMenu('ComponentPaletteItem', MenuAction,
MenuAction);
MenuService.UpdateMenuAccelerators(MenuService.MainMenu);
end;
end;

destructor TComMenus.Destroy;
begin
FMenutItem.Free;
FMenuAction.Free;
inherited;
end;

procedure TComMenus.DoExecute(Sender: TObject);
begin
// DoExecute is called when the the menu item is clicked.
end;

procedure TMyMenus.DoUpdate(Sender: TObject);
begin
// DoUpdate is called when the menu is displayed.
// Here you will want to set FMenuAction.Enabled to True or False or
// FMenuAction.Visible to True or False. I personally don't like it when menu
// items hide so don't change visible.

end;

Wednesday, April 9, 2008

Going Green


Copyright © 2005 Chris Bensen. All rights reserved.


Green is all the rage lately, and I'm all in favor of it for many reasons. I figured a green post was worthy since Earth Day is coming up. Lately it's been hard to go a few days without hearing about someone's carbon footprint and at 6'5" I have a pretty large carbon footprint. Seriously, I eat a lot of food.

One of my favorite reasons to have an environment around is so everyone I know, including myself, can live. My second favorite reason is so I can take photos like the one at the top of this post. I figured a photo of Mono Lake would be fitting for an environmental post such as this. Also pretty. I just got done editing it from a trip my dad and I made to the Sierras in October of 2005.

One of the things that bothers me about all the green talk is people and companies can buy down their "carbon footprint" with energy credits. I hear that Al Gore does this. It seems pretty silly since circulating more money inherently means growing the economy which is causing the environmental problems in the first place. Anyway, I'm digressing and I'm sure many people will have a comment or two about that.

Some companies like Patagonia go to great lengths to determine their impact on the planet with their Footprint Chronicles. I also think every company should join 1% For the Planet. There's also Google's Solar Panel Project. And you've probably seen Blackle where it is claimed that if Google were to change the default background color from white to black they'd save people from using loads of energy.

I've reduced the number of computers I use at CodeGear from three to two and they are set to wake-on-LAN so I can remote desktop into them. Somehow it doesn't seem even close to any of the projects I listed above but every little bit counts. Of course I do other things like recycle, drive as little as I can, ride my bike when I can, turn off lights etc. I probably could save some of you energy by optimizing the amount of memory that Delphi uses or something. Delphi already has the Twilight color scheme so I can't improve that.

And if it weren't difficult enough some things that are supposedly good for the environement really aren't. Time magazine has an article about ethanol and how is disastrous for the environment. Who really knows, but I do know I was thinking similar things when bio diesel became all the rage.

http://www.time.com/time/magazine/article/0,9171,1725975,00.html

Last week I dug a big hole for a tree in the front yard and I ran across a piece of styrofoam that was put into the ground over 10 years ago when the house was built. Needless to say it was a little dirty on the outside, but it was perfect on the inside. Nice! Good thing nearly everything comes packaged up in the stuff. I guess just buying less stuff will have an impact. But my government wants me to spend my tax credit. Hmmmm...

Of course one of the problems with computers and electronics is they are by their very nature tough on the environment. I've been trying to do business with environmentally friendly companies when possible. I try and look for companies that actually use less or have solar panels or just something that is actually energy efficient and not wasteful. Maybe they recycle for instance. A perfect example is aiso.net which is a web hosting company that I've been considering switching to. Has anyone had any experience with them? I'm looking for more companies that think like the ones I've listed here so I can do business with them.

What sorts of things have you or your company done to be more green?