Archive for the ‘components’ Category.

FireMonkey: Extending TFloatAnimation to support maximum loops

Background

In response to a QC report I wrote early last year I decided to implement a LoopCount property on the TFloatAnimation component.

Report No: 105140 Status: Open
Add a LoopCount property to the TAnimation class
http://qc.embarcadero.com/wc/qcmain.aspx?d=105140

Class Definition

  TJSCustomLoopCountFloatAnimation = class(TFloatAnimation)
  public
    type
      TAnimationLoopEvent = reference to procedure (Sender: TObject; const LoopNumber: Integer; var Cancel: Boolean);
  private
    FLoopCount: Integer;
    FCheckingLooping: Boolean;
    FOnLoop: TAnimationLoopEvent;
  protected
    FLoopsComplete: Integer;
    procedure FirstFrame; override;
    procedure DoLoop(var ACancel: Boolean); virtual;
    procedure ProcessAnimation; override;
  public
    constructor Create(AOwner: TComponent); override;
    property LoopCount: Integer read FLoopCount write FLoopCount default 3;
    property OnLoop: TAnimationLoopEvent read FOnLoop write FOnLoop;
  end;

Nothing that interesting in the new descendant. New property called LoopCount to control the number of loops and a new event that gets triggered each time a loop completes.

The published component publishes the new property and event but also changes the default values for two existing properties. It makes sense to set Loop to true when the new class is for enhancing the looping ability and if you’re looping, generally AutoReverse will be set to true.

  TJSLoopCountFloatAnimation = class(TJSCustomLoopCountFloatAnimation)
  published
    property AutoReverse default True;
    property Loop default True;
    property LoopCount;
    property OnLoop;
  end;

Implementation

I won’t post all of the code here because you can download from the link provided below, just a couple of snippets.

We need to override the FirstFrame method to initialise a couple of variables we use.

  • Checking to see if the LoopCount property is valid (raise an exception if it isn’t)
  • Initialise the variable to zero that counts the interactions
  • Make sure we are going to be checking the animation process for loops

Most of the work occurs in the overridden ProcessAnimation method.

procedure TJSCustomLoopCountFloatAnimation.ProcessAnimation;
var
  LCtx: TRttiContext;
  LType: TRttiType;
  LField: TRttiField;
  LCancel: Boolean;
begin
  inherited;
  if FCheckingLooping then
  begin
    LType := LCtx.GetType(Self.ClassInfo);
    if Assigned(LType) then
    begin
      LField := LType.GetField('FTime');
      if LField <> nil then
      begin
        if LField.GetValue(Self).AsExtended = 0 then
        begin
          Inc(FLoopsComplete);
          LCancel := False;
          if FLoopsComplete > 1 then
            DoLoop(LCancel);
          // The first time through, FTime is 0 so we need to offset this by
          // adding 1 when checking for completion
          if LCancel or (FLoopsComplete = LoopCount + 1) then
          begin
            LField := LType.GetField('FRunning');
            if LField <> nil then
              LField.SetValue(Self, False);
          end;
        end;
      end;
    end;
  end;
end;

Thanks to extended RTTI we can access a couple of private fields that we need to determine if a loop has been completed. This occurs when the FTime variable is zero. There is one issue with using this value and that is that the first “Loop” should be ignored since the first time ProcessAnimation is called FTime is zero so by the logic used, a loop has completed. This is why the DoLoop method is only called if the FLoopsComplete variable is greater than one.

Naturally it is possible to handle this one-off situation differently using a “First Time Through” variable but under the circumstances, I decided to go with the solution in place.

Once the LoopsComplete value is one greater than the LoopCount (refer to the above two paragraphs if you’ve already forgotten about why) the private field FRunning is set to False. Setting FRunning to false, stops the animation immediately.

Why not just call the public Stop method instead of going to the trouble of setting a private field? The answer to that is found in the ProcessTick method of the animation control (incidently, why isn’t this method virtual?).

  ...
  ProcessAnimation; // <==== We set FRunning to false here
  DoProcess;

  if not FRunning then
  begin
    if Assigned(AniThread) then
      TAniThread(AniThread).FAniList.Remove(Self);
    DoFinish;
  end;
  ...

By setting FRunning to false within our ProcessAnimation override, we are avoiding another frame being processed before the animation is stopped. This is because the Stop method calls ProcessAnimation and DoProcess as well.

Download

You can download the component and a cheesy demo application from the link provided. There is no package for the component to install it into your IDE, this is left as an exercise for the reader :-) .

Loop Animation Demo (short video – 39KB)

Download LoopCount Component and Demo

NOTE: Before downloading the source code you must agree to the license displayed below.

License Start




This space intentionally left blank…



License End

JSDialog Pack 2.0.021

A new version of JSDialog Pack was sent to customers earlier this month. If you haven’t received your Delphi XE3 compatible version of JSDialog Pack, let me know.

 

Release History

October (2.0.021)

- Add support for Delphi XE3
- Make non-modal dialog sheets move when the form is being moved or resized
- Fix combo box items not being set when default values specified
- Fix non-native progress bar state colours being incorrect

 

License Change

Like XE Plus Pack, JSDialog Pack as had a license change where new licenses are now lifetime licenses with no more to pay. You will continue to receive each new version with no additional payment. This is retrospective for the past 18 months of purchases. If you think you fall into this category, send me an email from the account used for the purchase.

For those that had been customers previously and decided not to renew, but would like to, contact me and we’ll work out the top up fee.

New licenses with lifetime support and upgrades are available for 90 Euros.

FireMonkey Style – TStyleTag

There appears to be an oversight by Embarcadero with the TStyleTag component not being registered for use.

TStyleTag is a handy little component that allows you to add it to a style definition and have it store an Integer, Float or String value. This is used in some of the default styles, one place being the TTrackBar where it is used to hold the default thumb size of the track item.

This allows you to retrieve the thumb size depending on the default style (Windows or Mac) and adjust your user interface depending on the value.

TStyleTag Component

I’ve created a package that your can compile and install into the IDE to register this component.

Download Package

The component doesn’t have to only be used in a style definition, you can drop it directly on your form if you have a use for its functionality.

NOTE: While the component is used in the default Windows and Mac styles, it doesn’t seem to be used in the other FireMonkey styles. Although I did only look in a couple of them. Perhaps something that will be address in an update.

 

 

XE3 Plus Pack

XE3 Plus Pack is now available for download.

 

This version supports XE3 and includes a new expert (detailed below), some minor enhancements plus some fixes.

- New expert called Watch Property Groups.

- The Bookmark Guide expert now defaults to suppressing editor bookmarks and aligning to the left of the editor.

- When displaying Options, the Visual Forms window is no longer displayed when not visible.

- When returning from viewing a form as text and there are errors treaming in the form an exception dialog would display repeatedly.

- Support Visual Forms captures for FireMonkey projects (the underlying structure of the form designer changed between XE2 and XE3).

- Logging Visual Forms messages would raise an exception on shutdown when the message view was not visible.

- Fix issue with Bookmark Guide not displaying when loading the IDE with no project.

- New command to automatically jump to the Library Paths options page. Add it to the IDE by customizing a toolbar.

 

Download

Download the 30 day trial – XE3 Plus Pack Trial Download

 

XE2 Plus Pack users

XE2 Plus Pack registration details also work with XE3 Plus Pack. Therefore there is no need to purchase XE3 Plus Pack if you are an existing XE2 Plus Pack customer.

 

Pricing change

The price for XE3 Plus Pack is still only 40 Euros and now includes a lifetime license. This change also applies to existing XE and XE2 Plus Pack holders.

 

Watch Property Groups

The Watch Property Group expert allows you to group a number of properties you generally watch for a specific object type and adds them all to the Watch List with a click of a button.

Watch Property Group

Steps Involved

  1. Define your property group
  2. Highlight the object instance in the code editor and display the Watch Property Group window. The default shortcut is Ctrl+Shift+W.
  3. Highlight the desired watch group to use and press enter (or the first toolbar button) in the Watch Property Group dialog to add a watch for each property in the defined group.

The Watch Property Group window can be docked in the IDE and saved to your debug layout so it is always where you want it.

Additional Information available in the online help guide: http://www.jed-software.com/help/WatchPropertyGroup/WatchPropertyGroup.html

 

XE Plus Pack – Release 8 (XE and XE2 versions)

A new release of XE Plus Pack is now available to download.

 

For Delphi XE – http://www.jed-software.com/files/XEPlusPackTrial.zip

For Delphi XE2 – http://www.jed-software.com/files/XE2PlusPackTrial.zip

NOTE: Update 4 must be installed for the Delphi XE2 version.

 

Available Experts

XE Plus Pack is a collection of IDE Experts, component editors and property editors available for either Delphi XE or Delphi XE2.

Currently XE Plus Pack consists of eight experts:

  1. Visual Forms (previously available as a separate product)
  2. Activate Project
  3. File Actions
  4. Remember IDE Tree Options
  5. Find Bar Alignment
  6. New Code Template
  7. Bookmark Guide (new in Release 6)
  8. Resolution Selector (new in Release 6)
  9. Mouse Scroll Form Designer (new in Release 8 )
  10. Structure Pane Enhancements (new in Release 8 )
  11. Help Shutdown (shutdown DExplorer.exe on IDE shutdown) (new in Release 8 )

 

Mouse Scroll Form Designer Image Mouse Scroll Form Designer

When the designed form gets too large to fit within the bounds of the embedded form designer, simply use the mouse wheel to scroll the hidden portion of the form into view.

  • This feature supports vertical and horizontal scrolling.
  • Hold down the control key to scroll horizontally if your mouse only supports vertical scrolling.

NOTE: In XE2, this expert doesn’t always work correctly with the FireMonkey designer. The FireMonkey designer doesn’t play very nice with the IDE and has a number of quirks and inconsistencies. I will continue to investigate making this work nicely in future releases.

 

Structure Pane Enhancements Structure Pane Enhancements

This expert has been totally driven by an XE Plus Pack user and would prove especially helpful for other users that use the Floating Form designer layout. This experts helps fix a number of deficencies when dealing with using the structure pane with the floating form designer.

  • Add an editor shortcut key combination to collapse the content of the structure pane.
  • Optionally make the structure pane the active window after the collapse has occurred.
  • Collapse the structure pane when navigating between source code editors.
  • (IDE BUG FIX) When using the floating form designer, make sure the source editor structure view is available when moving between the designed form and the source editor for the form.

 

Structure Pane Enhancements Help Shutdown

Makes sure the help system is shutdown when the IDE is closed. All instances of “dexplore.exe” are terminated.

 

What’s coming up

Release 9

  1. Options Import/Export utility.
  2. Path property editor for FireMonkey

Expected release date – July/August 2012

Release 10

Two new experts will be introduced.

  1. Smart Desktops
  2. Watch Property Groups

Expected release date – August/September 2012.

Disclaimer: Dates and features mentioned for upcoming versions may change.

JSDialog Pack 2.0.019

A new version of JSDialog Pack is now available to registered users with valid maintenance. If you haven’t received an email with the latest version – please contact me.

 

Highlighted Additions

This new version includes support for updated progress bar usage on the task bar under Windows 7.

New progress ShowOnTaskBar property

New ShowOnTaskBar property

Also included are new wrapper methods:

  • New overloaded version of VerifyMessage to support footers. (Declared in JSDialogs.pas)
  • New InputQueryVerification method which displays an input query style dialog with the verification checkbox visible. (Declared in JSEditDialogs.pas)
  • Also it is now possible to use your custom TJSEditDialog descendant for use in the edit dialog wrapper methods. Just set the new JSEditDialogClass variable in the JSEdtiDialog.pas unit to your new descendant.

 

Change Log

  • Add ability to display progress on the task bar under Windows 7
  • Fix memory management issue with non-modal dialogs
  • Fix unique name clashes
  • Support retrieving a button on the dialog by using its expected result value
  • Make sure dialog is updated when the glyph property is changed
  • Make sure using the SetProgressState method to change the state of the progress bar updates the progress bar in the dialog and also on the task bar
  • Change the UpdateProgress methods to functions that return the current value of the progress bar after being updated
  • Improve color usage in custom styled applications
  • New overload of the VerifyMessage wrapper method to allow setting footer information
  • Allow setting of the EditValue property in TJSEditDialog descendants
  • New event OnSetEditValue for TJSEditDialog descendants
  • Support opening files (prefix content location with “file” instead of “http“) when using the EditType of etHTML
  • New wrapper method InputQueryVerification that displays an InputQuery dialog with a checkbox on it
  • Allow specifying a default TJSEditDialog class to be used when invoking one of the TJSEditDialog wrapper methods. Set the JSEditDialogClass variable to change the default class.

 

 

18% off JSDialog Pack

In celebration of my daughter turning 18 in a few days, we are offering 18% off JSDialog Pack orders.

Just use the coupon code MADDIE18 to get the discount.

http://www.jed-software.com/jsd_purchase.htm

Just in time for the next release, which will occur before June.

http://www.jed-software.com/jsd.htm

Ribbon – using a ribbon style for a normal menu

Recently the following QC report was created:

Report No: 102419 (RAID: 289385)          Status: Open
RibbonStyleActnCtrls: No dropdown arrows of Actiontoolbar buttons
http://qc.embarcadero.com/wc/qcmain.aspx?d=102419

I noticed it and included the changes necessary to make it work. Since the ribbon functionality uses additional properties on TActionClientItem, these can be set for normal menu items to get the desired outcome. These additional properties are ignored by existing styles.

An alternate solution is a source code change that is also documented on the report. This source code change is not interface breaking, so you just need to copy the modified file into your applications folder.

 

As noted on the report, a ribbon style won’t work if the user selects the option in the ActionManager to use “large” images. This is due to the large button size on the ribbon being three times the height of a small button, instead of two that the ActionManager expects.

JSDialog Pack: Documentation

Work has almost been completed for the “Christmas Release” of JSDialog Pack. When I say almost completed there is still some testing to come and a couple of the new features are shaping nicely.

The new version will be released mid-december but I’ll go further into that when the release is closer.

One thing I’ve been concentrating on the past couple of days is updating the documentation. Unfortunately as a developer, I really like to write code, not write documentation. It is always good to have a good tool to complete this task efficiently and capable of producing a quality output (in multiple formats) in the end.

For my documentation I currently use Doc-O-Matic Professional version 6 (would like to upgrade to version 7, so you folks need to purchase some components ;-) ).

The single most important feature of this product I find is the QA View. It allows me to pin point exactly what properties, methods, classes and units are yet to be documented. It is always a relief to see no red boxes (or red boxes bordered by gray – not exported content). I’ve just finished getting all of the new items documented, as well as catching up on items that were not documented when first introduced.

A good habit I got into was creating the documentation while doing the coding. This is easy to do with Doc-O-Matic supporting a number of source documenting formats. Once I update the Doc-O-Matic project with the latest source version, I then make adjustments to the documentation in the inbuilt editor. It generally works very well and cuts down on the very important requirement to have the code documented for customers.

 

Some useless stats

Topic Count: 2510

Number of topics without content: should be zero

 

Web Help

Build Time: 2 minutes 12 seconds

Size of content: ~22MB

Time to upload to website: couple of hours (2682 files)

PDF Help

Build Time: 1 minute 55 seconds

Size of content: 7.56MB

Page count: 716

Html Help

Build Time: 2 minutes 38 seconds

Size of content: 3.45MB

 

While the PDF and Html Help formats are available to download from the website, I recommend using the online help since it can be updated and doesn’t require an additional download or change notification.

 

JSDialog Pack – Upcoming feature (custom command link colors)

A new feature in the next release of JSDialog Pack will be the ability to customise the colors used for command link buttons. Since the introduction of VCL Styles in XE2, dialogs can undertake a radial change in colors. While currently dialogs cater for this new feature, the next release will allow greater influence over the colors used for the dialog.

You can download a preview of the editor used to create, modify and save a color scheme. While the UI of this editor will most likely change – the file format shouldn’t need changes. So you can safely save any schemes you come up with for use when the feature is released.

http://www.jed-software.com/files/CommandLinkColorEditor.zip

Command Link Color Scheme - default

 

Command Link Color Scheme - custom