Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:43:39+00:00 2026-06-16T15:43:39+00:00

Quick question I cannot find any information on. On one of my components I

  • 0

Quick question I cannot find any information on.

On one of my components I am creating I have a value which is of Integer type.

I need to allow only values entered in the Object Inspector to be between 0-10, anything that falls outside of this range should display a message to say that the value inputted is not appropriate, and then return the focus back to the Delphi Object Inspector.

Example:

TMyComponent = class(TComponent)
private
  FRangeVal: Integer;
  procedure SetRangeVal(const Value: Integer);
public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
published
  property RangeVal: Integer read FRangeVal write SetRangeVal default 0;
end;

...

procedure SetRangeVal(const Value: Integer);
var
  OldValue: Integer;
begin
  OldValue := Value;
  if (Value < 0) or (Value > 10) then
  begin
    MessageDlg('Please enter a value between 0-10', mtError, [mbOK], 0);
    // FRangeVal := OldValue; ?? revert to the last value that worked
    // return focus back to property in Inspector ??
  end 
  else
  begin
    if Value <> FRangeVal then
    begin
      FRangeVal := Value;
    end;
  end;
end;

Do I need to raise some kind of special built in exception that I am unaware of maybe? The above works with my message box popping up, but focus to the culprit property in the Object Inspector is lost and I have to re click back into it to change the value again. If the entered value is bad I just want to show the message and return the focus so I can quickly enter a new value.

PS, code above was written in the web browser hence the original question showed I did not use the setter SetRangeVal for the property RangeVal – this was just a typing mistake.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:43:40+00:00Added an answer on June 16, 2026 at 3:43 pm

    First, if your property can only contain values between 0 and 10, don’t define it as a vague integer property; define it as a subtype with a defined range of values:

    type
      TMyComponentRangeValue = 0..10;
    
    TMyComponent = class(TComponent)
    private
      FRangeVal: TMyComponentRangeValue;
      procedure SetRangeVal(const Value: TMyComponentRangeValue);
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
    published
      property RangeVal: TMyComponentRangeValue read FRangeVal 
        write SetRangeVal default 0;
    end;
    

    Now you can let the compiler and IDE handle checking for allowable values without doing anything yourself. (The IDE wlll handle the exception and reverting back to the previous value if an invalid value is entered.)

    procedure TMyComponent.SetRangeValue(const Value: TMyComponentRangeValue);
    begin
      if Value <> FRangeValue then
        FRangeValue := Value;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a quick question, on which I cannot find a good reference, especially with
A quick question. Have done some googling, but still cannot find the answer: what
Quick question, I have the following string which is a coma separated list of
quick question - I have my first view which is going to be the
so I have a quick question that I cannot figure out. I have some
just a quick question. I cannot find anything relating to this since I don't
Quick question about WordPress. I've been Googling all over the place and cannot find
I have a quick question regarding the scope of dynamic arrays, which I assume
Quick question, indexof() find the first occur position of the string character? what about
Quick question (and sorry if it's already been asked, I have looked but couldn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.