Quick question. I cannot find any information.
On one of my components that I create, I have a value that is of type Integer.
I need to allow only the values entered in the Object Inspector, between 0-10, everything that falls outside this range should display a message to say that the entered value does not fit, 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 special built-in exception that I don’t know about, maybe? The above works with my message box, but the focus on the fault property in the Object Inspector is lost, and I need to click back again to change the value again. If the entered value is bad, I just want to show the message and return focus so that I can quickly enter the new value.
PS, the code above was written in a web browser, so the original question showed that I did not use setter SetRangeVal for the RangeVal property - it was just an input error.
user1175743
source share