Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Does anyone have another tip. TEdit UpperCase



Permlink Replies: 3 - Last Post: Jul 4, 2014 3:30 AM Last Post By: Jeremy North
Alax Filho

Posts: 6
Registered: 7/4/14
Does anyone have another tip. TEdit UpperCase
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 3, 2014 12:12 PM
Form -> 2 TEdit's
Only way I was able to enter uppercase TEdit
Does anyone have another tip?

code: OnChangeTracking -> Edit2

procedure TForm11.Edit2ChangeTracking(Sender: TObject);
var
ntxt: String;
begin
ntxt := Edit2.Text;
Edit2.OnChangeTracking := nil;
Edit2.Text := '';
Edit2.Text := UpperCase(ntxt);
Edit2.OnChangeTracking := Edit2ChangeTracking;
Edit1.SetFocus;
Edit2.SetFocus;
Edit2.SelStart := Length(Edit2.Text);
end;
Alax Filho

Posts: 6
Registered: 7/4/14
Re: Does anyone have another tip. TEdit UpperCase
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 3, 2014 12:24 PM   in response to: Alax Filho in response to: Alax Filho
Just got better.
Thks.

procedure TForm11.Edit2ChangeTracking(Sender: TObject);
var
ntxt: String;
begin
ntxt := Edit2.Text;
Edit2.OnChangeTracking := nil;
Edit2.Text := '';
Edit2.Text := UpperCase(ntxt);
Edit2.OnChangeTracking := Edit2ChangeTracking;
Edit2.GoToTextEnd;
end;

Alax Filho wrote:
Form -> 2 TEdit's
Only way I was able to enter uppercase TEdit
Does anyone have another tip?

code: OnChangeTracking -> Edit2

procedure TForm11.Edit2ChangeTracking(Sender: TObject);
var
ntxt: String;
begin
ntxt := Edit2.Text;
Edit2.OnChangeTracking := nil;
Edit2.Text := '';
Edit2.Text := UpperCase(ntxt);
Edit2.OnChangeTracking := Edit2ChangeTracking;
Edit1.SetFocus;
Edit2.SetFocus;
Edit2.SelStart := Length(Edit2.Text);
end;
Alax Filho

Posts: 6
Registered: 7/4/14
Re: Does anyone have another tip. TEdit UpperCase
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 3, 2014 12:33 PM   in response to: Alax Filho in response to: Alax Filho
This is the correct

procedure TForm11._OnChangeTracking(Sender: TObject);
var
ntxt: String;
begin
if (Sender As TEdit).IsFocused then
begin
ntxt := (Sender As TEdit).Text;
(Sender As TEdit).OnChangeTracking := nil;
(Sender As TEdit).Text := '';
(Sender As TEdit).Text := UpperCase(ntxt);
(Sender As TEdit).OnChangeTracking := _OnChangeTracking;
(Sender As TEdit).GoToTextEnd;
end;
end;

Alax Filho wrote:
Form -> 2 TEdit's
Only way I was able to enter uppercase TEdit
Does anyone have another tip?

code: OnChangeTracking -> Edit2

procedure TForm11.Edit2ChangeTracking(Sender: TObject);
var
ntxt: String;
begin
ntxt := Edit2.Text;
Edit2.OnChangeTracking := nil;
Edit2.Text := '';
Edit2.Text := UpperCase(ntxt);
Edit2.OnChangeTracking := Edit2ChangeTracking;
Edit1.SetFocus;
Edit2.SetFocus;
Edit2.SelStart := Length(Edit2.Text);
end;
Jeremy North

Posts: 402
Registered: 9/20/99
Re: Does anyone have another tip. TEdit UpperCase
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 4, 2014 3:30 AM   in response to: Alax Filho in response to: Alax Filho
Alax Filho wrote:

This is the correct

procedure TForm11._OnChangeTracking(Sender: TObject);
var
ntxt: String;
begin
if (Sender As TEdit).IsFocused then
begin
ntxt := (Sender As TEdit).Text;
(Sender As TEdit).OnChangeTracking := nil;
(Sender As TEdit).Text := '';
(Sender As TEdit).Text := UpperCase(ntxt);
(Sender As TEdit).OnChangeTracking := _OnChangeTracking;
(Sender As TEdit).GoToTextEnd;
end;
end;

This is not an efficient coding style. For one, if the Sender isn't a
TEdit an exception will be raised which isn't a good thing under
mobile. Another is that performing all of those "as" casts is expensive.

procedure TForm11._OnChangeTracking(Sender: TObject);
var
ntxt: String;
LEdit: TEdit;
begin
if Sender is TEdit then
begin
LEdit := TEdit(Sender);
ntxt := LEdit.Text; // why do you need this temp variable?
LEdit.OnChangeTracking := nil;
LEdit.Text := '';
LEdit.Text := UpperCase(ntxt);
LEdit.OnChangeTracking := _OnChangeTracking;
LEdit.GoToTextEnd;
end;
end;

Without testing I'd change it to be something like this (and bug
embarcadero if this didn't work)

procedure TForm11._OnChangeTracking(Sender: TObject);
var
LEdit: TEdit;
begin
if Sender is TEdit then
begin
LEdit := TEdit(Sender);
LEdit.OnChangeTracking := nil;
try
LEdit.Text := UpperCase(LEdit.Text);
LEdit.GoToTextEnd;
finally
LEdit.OnChangeTracking := _OnChangeTracking;
end;
end;
end;

I'd try it out but I am uninstalling XE6 at the moment.

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02