test

progging - To wander about and beg; to seek food or other supplies by low arts; to seek for advantage by mean shift or tricks.
progging - Programmer slang for writing computer code.

søndag 11. september 2011

Bazaar Bug

At one point Bazaar started acting up. The command line tool worked just fine, but I like to use TortoiseBzr when commiting to be able to easily check all the changes I've done before the commit. But both TortoiseBzr and Bazaar Explorer only returned an error when starting up.

So I filed a bug at launchpad, and within less than an hour after I had registers at launchpad (unfortunately, you have to register to be able to submit a bug report), I got an email with a solution. It was simply a config file (qbzr.conf) that was corrupt and all that was needed was to delete it. Great support work though!!!


By the way, the problem occurred after a windows blue screen...

Delphi: General method to check if key is pressed

To check if a specific key is pressed you can use the GetKeyState method.

type
  TUtility = class
  public
    class function CheckKeyPressed(key: Integer): Boolean;
    class function ShiftKeyPressed(): Boolean;
    class function CtrlKeyPressed(): Boolean;
    class function AltKeyPressed(): Boolean;
  end
One method can check any key you want using virtual key codes:
// Helper methods to check various key states
class function TUtility.CheckKeyPressed(key: Integer): Boolean;
begin
  //The return value of GetKeyState specifies the status of the specified virtual key, as follows:
  //
  //If the high-order bit is 1, the key is down; otherwise, it is up.
  //If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled
  //if it is turned on.
  // The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any)
  // on the keyboard will be on when the key is toggled, and off when the key is untoggled.
  //
  // Check high-order of state
  Result := (GetKeyState(key) and $80) <> 0;
end;
...and specific methods for the most interesting keys can be made:
// Helper methods to check various key states
class function TUtility.ShiftKeyPressed(): Boolean;
begin
  Result := CheckKeyPressed(VK_SHIFT);
end;

class function TUtility.CtrlKeyPressed(): Boolean;
begin
  Result := CheckKeyPressed(VK_CONTROL);
end;

class function TUtility.AltKeyPressed(): Boolean;
begin
  Result := CheckKeyPressed(VK_MENU);
end;

tirsdag 6. september 2011

Position the legend in the upper right corner of a TeeChart chart


The TeeChart has many ways of position the Legend on the chart. You can set it to custom and make it a percentage of the width of the chart, but simply putting it on the right side of the chart and make it stay there when the form was resized, was not straight forward.






The solution was to handle the ChartGetLegendPos and ChartGetLegendRect events.
// The following two event handlers are here to position the legend (and it's text)
// in the upper right corner of the chart. This was not possible to simply configure
// in the TeeChart editor.
procedure TFrm.ChartGetLegendPos(Sender: TCustomChart;
  Index: Integer; var X, Y, XColor: Integer);
var
  diff: Integer;
begin
  diff := X - XColor;
  XColor := Sender.Legend.Left + 7;
  X := XColor + diff;
end;

procedure TFrm.ChartGetLegendRect(Sender: TCustomChart;
  var Rect: TRect);
var
 w, h: Integer;
begin
  w := Rect.Right - Rect.Left;
  h := Rect.Bottom - Rect.Top;
  Rect.Top := Sender.ChartRect.Top;
  Rect.Bottom := Rect.Top + h;
  Rect.Left := Sender.ChartRect.Left + (Sender.ChartWidth - w);
  Rect.Right := Rect.Left + w;
end;

Define your custom TColor type in Delphi

Do define your own custom color in Delphi, do this:

const
  clChartRed = TColor($B3B3FF);       // 70 % gradient Red on White
  clChartYellow = TColor($B3FFFF);    // 70 % gradient Yellow on White
But remember that Delphi defines the colors as BGR and not the usual RGB so remember to swap numbers.
So the color red would be:
const
  clRed = TColor($0000FF);       // Red