TAdvSpinEdit vs TSpinEdit: Key Differences and When to Use Each

Troubleshooting Common TAdvSpinEdit Issues and FixesTAdvSpinEdit (part of TMS Software’s component packs for Delphi/C++Builder) is a feature-rich numeric input control that extends the standard TSpinEdit with styling, formatting, and behavior options. While powerful, developers sometimes encounter issues when integrating it into projects. This article covers common problems, diagnostic steps, and practical fixes to get TAdvSpinEdit behaving correctly.


1. Control doesn’t appear at runtime or is invisible

Symptoms:

  • The control is visible at design time but not at runtime.
  • The control’s size or position might be wrong, or it may be hidden behind other controls.

Common causes and fixes:

  • Parent/Owner mismatch: Ensure Parent is set to the form or container (Panel, GroupBox). In code, set AdvSpinEdit.Parent := Self or the correct container after creation.
  • Align or Anchors: Check Align and Anchors properties. Align := alClient on a wrong container can hide it. Temporarily set Align := alNone to confirm.
  • BringToFront/SendToBack: Call AdvSpinEdit.BringToFront to ensure it’s not behind other controls.
  • Visible property: Confirm Visible = True and Enabled = True.
  • Auto-create timing: If creating dynamically, create the control after the container exists (e.g., in OnCreate of the form, not in initialization sections).
  • Tab order and Z-order issues: Verify Component->ZOrder or use SendToBack/BringToFront appropriately.

2. Up/Down buttons not responding

Symptoms:

  • Clicking spinner buttons doesn’t change value.
  • Mouse clicks appear to register but no change occurs.

Common causes and fixes:

  • ReadOnly or Locked: Check ReadOnly or ReadOnlyColor properties; set ReadOnly := False.
  • OnChange/OnClick event handlers interfering: Event handler code may revert or block changes. Temporarily remove handlers to isolate behavior. If using OnValidate or OnChange to correct values, ensure they don’t set Value back unconditionally.
  • Increment set to zero: Ensure Increment (or Step) property > 0.
  • Focus-related code: If your code moves focus in response to clicks, it may interrupt the control’s default behavior. Defer focus changes (use PostMessage or a short timer) rather than immediate shifts.
  • Mouse capture issues: If other components or global hooks capture mouse, spinner clicks may not be delivered. Test in a minimal project.

3. Incorrect formatting or localization of numbers

Symptoms:

  • Decimal separator, thousands separator, or currency formatting is wrong.
  • Displayed number differs from internal value.

Common causes and fixes:

  • DecimalSeparator / ThousandSeparator settings: TAdvSpinEdit can respect VCL’s FormatSettings or its own Format property. Set FormatSettings.DecimalSeparator := ‘.’ (or as needed) or adjust TAdvSpinEdit.Format to an appropriate mask (e.g., ‘#,##0.00’).
  • Use of Float vs Integer properties: Make sure you’re reading/writing the correct property (ValueFloat, Value, IntValue, Text). For floating-point input use ValueFloat; for integers use Value.
  • Locale changes at runtime: If your app changes Locale or FormatSettings dynamically, call AdvSpinEdit.Invalidate and/or reassign DisplayFormat so it reapplies formatting.
  • Precision/DecimalPlaces: Check DecimalPlaces or Precision settings to ensure rounding/display match expectations.

4. Clipboard paste or keyboard input issues

Symptoms:

  • Pasting numbers yields invalid text or discarded input.
  • Keyboard input of decimal separator doesn’t work.

Common causes and fixes:

  • AllowedChars or Filter settings: Verify AllowedChars or any input mask isn’t blocking characters like ‘-’ or decimal separator. Adjust AllowedChars to include necessary symbols.
  • OnKeyPress handlers: Custom key handling may block certain keys. Ensure OnKeyPress allows digits, backspace, minus, and decimal separator. Example minimal filter:
    
    if not(CharInSet(Key, ['0'..'9', DecimalSeparator, '-', #8])) then Key := #0; 
  • Clipboard format differences: When pasting from other locales, the clipboard string may use a different decimal separator or contain non-breaking spaces as thousands separators. Preprocess pasted text in OnPaste or OnChange: replace non-breaking spaces and alternate separators before assigning to Value.
  • MaxLength and Range: MaxLength may truncate pasted text; Range (Min/Max) can reject values silently — validate and show feedback to the user.

5. Performance problems with many controls or frequent updates

Symptoms:

  • UI becomes sluggish when updating many TAdvSpinEdit controls.
  • Bulk changes flicker or are slow.

Common causes and fixes:

  • Repainting overhead: Wrap bulk updates in BeginUpdate/EndUpdate if available, or disable redrawing:
    
    SendMessage(Form.Handle, WM_SETREDRAW, WPARAM(False), 0); try // bulk changes finally SendMessage(Form.Handle, WM_SETREDRAW, WPARAM(True), 0); Invalidate; end; 
  • Frequent OnChange events: Temporarily disconnect OnChange or use a boolean flag (Updating := True) to suppress event handling during batch updates.
  • Complex custom drawing: If using OnDraw or owner-draw features, optimize drawing code and cache resources (fonts, bitmaps).
  • Virtualization: If you need many numeric editors in a scrolling list, consider virtualizing the UI (reuse controls) or using a grid with in-place editors rather than dozens/hundreds of individual controls.

6. Value not persisting or unexpected value on load/save

Symptoms:

  • Values appear correct at runtime but revert after saving/loading or when re-opening the form.
  • Values saved to file/registry are incorrect.

Common causes and fixes:

  • Wrong read/write property: Save and load the same property type you use at runtime (Value vs ValueFloat vs Text). Prefer ValueFloat for floating values.
  • Timing of load/save: If you load values before controls are fully created or after something resets them, values may be overwritten. Load persisted values in Form.OnShow or after form/component streaming completes.
  • Streaming limitations: If using DFM streaming to persist default property values, ensure properties are published and have default declarations. Otherwise persist programmatically to INI/Registry/Settings using consistent types.
  • Precision/rounding on save: When saving floats, format with sufficient precision (e.g., use FloatToStrF with ffFixed and a high DecimalPlaces) or store as binary if precision is crucial.

7. Styling, theme, or VCL styles problems

Symptoms:

  • Control appearance is inconsistent under VCL styles.
  • Custom colors or glyphs are ignored.

Common causes and fixes:

  • VCL styles override: VCL styles can override color/brush settings. Use the control’s StyleElements and StyleLook properties where available to opt out of style parts, or set UseSystemFont/UseSystemColors as appropriate.
  • Custom glyphs not scaled: Ensure glyphs match current DPI/scaling or provide multiple-size resources. Use TMS guidance for high-DPI assets.
  • Transparency and background blending: If background shows incorrectly, set ParentBackground/ParentColor or adjust Transparent property. Redraw issues can be fixed with Invalidate or Refresh after style changes.

8. Events firing in unexpected order

Symptoms:

  • OnChange, OnExit, OnValidate, or OnClick run in a different order than expected, causing logic errors.

Common causes and fixes:

  • Focus change triggers: Moving focus programmatically can trigger OnExit/OnValidate. Use Validate or PostMessage to defer logic that changes focus.
  • Property-setting side effects: Setting Value in code can trigger OnChange. Use a guard variable (Updating := True) to ignore events during programmatic changes.
  • Windows message interleaving: Complex message handling or modal dialogs can change expected ordering. Simplify event logic and avoid heavy UI operations inside input events.

9. Compatibility problems between versions or different TMS packs

Symptoms:

  • Project compiles with one TMS version but behaves differently with another.
  • Properties/events missing after upgrade.

Common causes and fixes:

  • Version-specific changes: Review TMS release notes — properties and behaviors sometimes change. Adapt code to new property names or semantics.
  • Name collisions: If multiple component libraries define similarly named components, ensure unit references in uses clause are ordered correctly to resolve the correct class.
  • Recompile packages: After upgrading TMS, recompile any runtime packages and the project to avoid mismatched DCU/RSP files.

10. Debugging strategy and checklist

Use this concise checklist when troubleshooting:

  • Reproduce the issue in a minimal new project.
  • Check property grid for ReadOnly, Visible, Enabled, Increment, Min/Max, DecimalPlaces.
  • Temporarily remove event handlers to isolate code-caused issues.
  • Test with VCL styles off to rule out theming problems.
  • Use logging or breakpoints in OnChange/OnClick/OnValidate to trace execution flow.
  • Verify you’re using the correct property (Value vs ValueFloat vs Text) for your needs.
  • Confirm TMS version compatibility and recompile packages after upgrades.

Example snippets

Setting decimal separator and parsing pasted clipboard text:

uses   SysUtils, Vcl.Controls; procedure TForm1.FormCreate(Sender: TObject); begin   FormatSettings.DecimalSeparator := '.';   AdvSpinEdit1.DecimalPlaces := 2; end; procedure TForm1.AdvSpinEdit1OnPaste(Sender: TObject; const S: string); var   Clean: string; begin   Clean := StringReplace(S, #160, ' ', [rfReplaceAll]); // non-breaking spaces   Clean := StringReplace(Clean, ',', FormatSettings.DecimalSeparator, [rfReplaceAll]);   AdvSpinEdit1.Text := Clean; end; 

Suppressing OnChange during programmatic updates:

procedure TForm1.UpdateValues; begin   FUpdating := True;   try     AdvSpinEdit1.Value := 10;     AdvSpinEdit2.ValueFloat := 3.1415;   finally     FUpdating := False;   end; end; procedure TForm1.AdvSpinEdit1Change(Sender: TObject); begin   if FUpdating then Exit;   // normal handling end; 

Final notes

Most issues with TAdvSpinEdit stem from property configurations, event-handling code, localization/formatting, or interaction with VCL styles and DPI. Start with a minimal reproduction, inspect properties and event handlers, and use guards when updating values programmatically. If a bug appears tied to a specific TMS version, consult TMS changelogs and consider filing a support ticket with a small reproducible project.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *