Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jump to end of TDBEdit 1

Status
Not open for further replies.

roo0047

Programmer
Jul 31, 2004
533
US
I have a TDBEdit where users enter a temperature value, usually something like "-40°C" or "+32°F". Pasting the deg-symbol has always been a PITA, so I've added a small SpeedButton above the edit control which will paste the symbol with the following:
Code:
procedure TTenCvnForm.DegBtnClick(Sender: TObject);
begin
  if pos('°', EditTemp.Text) < 2 then
    EditTemp.Text:= EditTemp.Text + '°';
  ActiveControl:= EditTemp;
end;
But when control is passed back to EditTemp, the cursor is now at the beginning instead of the end. How do I force it to the end so it's in the right place when the the user presses 'F' or 'C'?

Roo
Delphi Rules!
 
Here are a couple of stabs:

Does EditTemp.SetFocus work differently?
Send a windows message/send keys to press {End}
Does a TDBRichEdit/TDBMemo work any better (you usually have better control options).

 
Does EditTemp.SetFocus work differently?
no change
Send a windows message/send keys to press {End}
PostMessage(EditTemp.Handle, vk_end, 0, 0); didn't work. :-(
Does a TDBRichEdit/TDBMemo work any better (you usually have better control options).
It's a char(7) field to a table so I'd rather stick with TDBEdit. TEdit does the same thing, BTW.

Thanks for the reply though... Seems like it would be simple but I'm just brain-dead today and it has me stumped.

Roo
Delphi Rules!
 
Code:
EditTemp.AutoSelect := False;
EditTemp.SelStart:=Length(EditTemp.Text);

Hope this can help
Gianni
 
A better explanation on what i mean:

You can set EditTemp property AutoSelect to False;

In EditTemp.OnEnter event, set: EditTemp.SelStart:=Length(EditTemp.Text);

gianni
 
Why not:
Code:
procedure TForm1.EditTemp(Sender: TObject);
var degset :  set of 'C'..'F';
begin
  if EditTemp.Text = '' then Exit;
  degset := ['C','F'];
  if EditTemp.Text[Length(EditTemp.Text)] in degset then
    Begin
      if Pos('°',EditTemp.Text) = 0 then
        Begin
          EditTemp.Text := Leftstr(EditTemp.Text,Length(EditTemp.Text)-1)+'°'+Rightstr(EditTemp.Text,1);
        End;
    End;
End;

so you don't need SpeedButton
Gianni
 
Thanks gcaramia! EditTemp.SelStart:=Length(EditTemp.Text) is exactly what I was looking for and I knew it was something really simple.

BTW: I added a hint to the button: "You can skip this by just pressing [C] or [F]", then added:
Code:
procedure TTenCvnForm.EditTempKeyPress(Sender: TObject; var Key: Char);
begin
  Key:= upcase(Key);
  if (Key = 'C') and (pos('°',EditTemp.Text) = 0) then begin
    EditTemp.Text:= EditTemp.Text + '°C';
    Key:= #0
  end else if (Key = 'F') and (pos('°',EditTemp.Text) = 0) then begin
    EditTemp.Text:= EditTemp.Text + '°F';
    Key:= #0
  end
end;
All works great and thanks again!
star.gif


Roo
Delphi Rules!
 
Why not have two speed buttons?

One would have °C and the other one °F. Pressing either of the buttons would add the appropriate text to the end of the TDBEdit control, possibly range check the temperature and perhaps tab to the next field.

This might improve usability and speed up data entry.

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top