Jump to content


Photo

Problem with TNxEdit and TextAfter

TNxEdit TextAfter

  • Please log in to reply
1 reply to this topic

#1 m610

m610
  • Members
  • 33 posts

Posted 10 March 2016 - 04:06 AM

These are two separate problems.

 

1. TextAfter

I discovered a while back that with TNxNumberEdit if I use text containing a period in the TextAfter property that an error is produced. It's been a while, so I forget exactly the error, but it is probably a conversion problem. For example, "sec" is OK, but 'sec." is not.

 

2. TNxEdit

I group the responses to the OnChange and OnSelect events of various editors into one procedure. With so many editors in a form I find this helpful. I use the editor's TAG property and (Sender is .. ) to match the editor with what needs to be done.

 

I'll attach the full code that I am using, but will include a summary here.

 

Procedure SomethingChanged(Sender:TObject);

var Idx: integer;

var iValue: integer;

var fValue: single;

begin

 

  Idx:=(Sender as TComponent).tag;

 

// I use Idx, iValue, fValue for my typing/reading convenience.

 

// I'm using TNxComboBox to get various types of values from the user, including text and the item index.

if (Sender is TNxComboBox) then

begin

  iValue:= (Sender as TNxComboBox).ItemIndex;

  case IDX of

    1: X:= iValue;

    2: Y:= (Sender as TNxComboBox).Items[iValue];

  end;

end;

 

// I'm using TNxEdit to get numbers from the user. I needed to be able to use exponential notation for these numbers.

if (Sender is TNxEdit) then

begin

  fValue:= StrToFloat(Sender as TNxEdit).AsFloat;

  case IDX of

    3: S:= fValue;

    4: T:= fValue;

  end;

end;

 

// Here of course I am getting only numbers from the user.

if (Sender is TNxComboBox) then

begin

  fValue:= (Sender as TNxNmberEdit).AsFloat;

  case IDX of

    1: A:= fValue;

    2: B:= fValue;

  end;

end;

 

end;

 

The problem here is that whenever the Sender is a TNxComboBox or TNxEditBox the section meant to handle the TNxEdit events is used. For example, after going through the part meant for TNxComboBox, the TNxEdit code is also executed. The same occurs when the Sender is a TNxNumberEdit component. It's as if TNxEdit is also a TNxComboBox and TNxNumberEdit. The way I have written the code here StrToFloat fails when the text is not a number or if it is a number and includes a TextAfter string.

 

The workaround is easy enough, but figuring this out took me a lot of time. I figured you might like to know about it and fix it.

 

Mike

Attached Files



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 11 March 2016 - 04:46 PM

Hi Mike,

I will check problem with dot inside TextAfter. It may be that it confuses it with DecimalSeparator (but not sure yet).

Problem with these events are since they are from very early versions long ago. They can be quite mind-bending as well :( You have events from TEdit ascendant which you can't use, events for Columns etc.

This why I try to make it better in v6 since start.

Today I have created new Demo in Demos\Next Standard\Delphi XE6\NxComboBox6 Events Demo sub-folder where users will be able to see how exactly events work.

If you have time and interests, you can check this demo later today and tell me if you have any comments how it can be improved.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.





Also tagged with one or more of these keywords: TNxEdit, TextAfter

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users