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.

mandag 21. januar 2013

Multiple TFrame's on a form

I got a run-time error in my application when I had added two instances of the same TFrame on the same form. The error message looked like this:
A component named MyFrame already exists

Fair enough, but the thing was that only one of the frames was called 'MyFrame'. The other one was called 'MyFrame2'.

Apparently, the problem is that one of the two frames on my form using the default name as it is in unit that declares the frame TMyFrame.

So, if you only uses one frame of type TMyFrame on the form, it is okay to call it MyFrame, but if you have two ore more, none of them can be called MyFrame.

Lesson learned!

onsdag 22. februar 2012

Quick list for adding a new repository

Normally, we work in a centralized workflow and here are a few steps for setting up a new repository for a project.

1. Create repository on the server (v:\bzr):

bzr init-repo --no-trees v:\bzr\MyNewProject

bzr init v:\bzr\MyNewProject
  Created a repository tree (format: 2a)
  Using shared repository: V:/bzr/MyNewProject/


2. Checkout repository on each development machine:

c:\Projects>bzr init-repo --trees MyNewProject
Shared repository with trees (format: 2a)
Location:
  shared repository: MyNewProject



c:\Projects\MyNewProject>bzr checkout v:\bzr\ MyNewProject 8.9x


3. On the machine that has any existing code to add:
- Copy or create a .bzrignore file first!

c:\Projects\MyNewProject>bzr add (--dry-run)
c:\Projects\MyNewProject>bzr commit -m "initial import"

Moving a Bazaar repository

I've been using Bazaar in a centralized workflow, with a repository on a server. I wanted to move the repository to a different server that will be backed up. This was as simple as copy the complete bzr repository folder from server A to server B, and then do a bzr switch on each of the locations where I had been working on the project.

C:\Projects\ABC>bzr switch v:\bzr\ABC
Tree is up to date at revision 145.
Switched to branch: V:/bzr/ABC/


Remember to commit any changes you have first!

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;