Thursday, 28 June 2018

Delphi features that I was not aware of

The other day I came across a feature of Delphi that in my 18+ years of using Delphi have never used, it is the 'Hide Non-Visual Components' (Ctrl+H) when design a form. I came across this because another Developer pointed out to me that he could not see the menu controls on a form. I thought there might be an option somewhere and on the right click menu was the option.

I have never used this feature and it got me thinking what other features are there that I am not aware of (Delphi Berlin) and are there any that I might use. Here are 2 lists of features I have since discovered, one list is for ones that I think are pointless and I would never use and the other for features that I believe are useful.

Features I've found that I think I will never use:
  1. Quick Icon - right click menu option in the form designer.
  2. Quick Edit - right click menu option in the form designer.
  3. Flip Children - right click menu option in the form designer. I think I'v seen this before, but have never used it and cannot think of when I would.
  4. Lock Controls - main menu > edit. This feature locks some controls on forms from resizing and moving. This feature has strange behaviour as it sometimes locks the resize, but not the ability to move the control, try locking the controls, closing the form and opening it again and the size of the controls cannot be changed but the positions can. Clearly never been through QA.
  5. Scale - main menu option > edit. This gives the developer the feature to scale a form and it's controls be a percentage. 

Features I've found that could be useful:
  1. Surround > Region - right click menu option in the code editor. 
  2. Search for Usages - right click menu option in the code editor.  
This is just a brief list of features that I have found over the last couple of day that I was not aware of, most of which I will never use. There are most likely other features in Delphi I have yet to discover that are of some use. 

Tuesday, 19 June 2018

Why does TSpinEdit not enforce the MaxValue property?

With a TSpinEdit there is a property called 'MaxValue', from the name it implies that the maximum value for the control is what value you set for the property, but this is not the case. The property sets the maximum value for using the spin edit buttons, a user can enter a value exceeding the maximum value by using the keyboard up to the value of an Int64 (9,223,372,036,854,775,807).

This seems to have been done by design, but I cannot see a valid reason for this and it could be a little dangerous when being used to control the valid values entered.  

By putting the following in the OnChange event I've managed to get around the problem. Not sure if there is a better solution. 

if (Sender is TSpinEdit) then
begin
    if (Sender as TSpinEdit).Value > (Sender as TSpinEdit).MaxValue then
    begin
        (Sender as TSpinEdit).Value := (Sender as TSpinEdit).MaxValue;
    end;
end;