Recent

Author Topic: [SOLVED] Changing TEdit to an integer  (Read 41027 times)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Changing TEdit to an integer
« Reply #30 on: November 20, 2013, 03:46:52 am »
Almost everything that I write is for RightToLeft languages like Hebrew and Arabic (the language is written Right To Left) so not much of my code would be of use to you.  But just to see the logic, here is a bit of code.  Don't bother trying to compile it. It has calls to code you don't have.

Code: [Select]
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  );
var
  C: TControl;
begin
  C:= TForm(Sender).ActiveControl;
  if
    (IsMirrored(C))and(C is TPageControl)or
    (IsMirrored(C))and(C is TStringGrid)
  then
    case Key of
      VK_Right: Key:= VK_Left;
      VK_Left : Key:= VK_Right;
    end;
end;

You can get very sophisticated, but usually that means poor design and code that is hard to read and even harder to modify.
Lazarus Trunk / fpc 2.6.2 / Win32

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Changing TEdit to an integer
« Reply #31 on: November 22, 2013, 12:51:37 am »
Do appreciate the help!

Can I put this "GoodKeys = [...]" routine in one control Event OnKeyDown and then select it through other Event OnKeyDown options that I might want the same action?  I'm trying to figure out how to code it once and call it for each field the user has to complete.

Thanks!

(Avishai - nice pic!)
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Changing TEdit to an integer
« Reply #32 on: November 22, 2013, 02:24:11 am »
Yes, just use this code for the first one.

Code: [Select]
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key = VK_RETURN then Key := VK_TAB;
end;

Then select the others and set them to this event.  You can select more than one control at once by holding down the Shift key while selecting them.
Lazarus Trunk / fpc 2.6.2 / Win32

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Changing TEdit to an integer
« Reply #33 on: November 22, 2013, 05:39:36 am »
Avishai - that takes care of the RET and TAB VK_s.  Thanks.  I'll give it a try for error-checking the char and int inputs.

Almost all of my old stuff doesn't work anymore...  :(

Code: [Select]
{************   SET CURRENT DRIVE   ***************}

procedure set_current_drive(drive : byte);

var regs : registers;
begin
  with regs do
    begin
      ax := $e00;
      dx := drive;
      msdos(regs);
    end;
end;     

I have to rethink each step!!

Appreciate the help!

< S >
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

Bart

  • Hero Member
  • *****
  • Posts: 5727
    • Bart en Mariska's Webstek
Re: Changing TEdit to an integer
« Reply #34 on: November 22, 2013, 02:11:14 pm »
Use SetCurrentDirectory instead (if you do it like SetCurrentDirectory('C:') it behaves just like the old SteCurrentDrive code).

Bart

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Changing TEdit to an integer
« Reply #35 on: November 23, 2013, 06:43:30 pm »
Just found that.  Thanks!
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Changing TEdit to an integer
« Reply #36 on: November 23, 2013, 09:12:34 pm »
Ok....  to minimize writing code... :-[

Logically, I should be able to call this Event in each TEdit procedure.  I changed the word TEdit to Form for my readability since I want the action to be used in all of the data input areas on the form:

Code: [Select]
procedure TClients.FormKeyDown(Sender: TObject; var Key: Word);
begin
  if Key = VK_RETURN then Key := VK_TAB;
end;
 

When added to any procedure's properties, I received the error:  "The method 'FormKeyDown' is incompatible with this event (OnKeyDown)".  Why?  All I did was rename the procedure.

In trying to cleanup all Events' OnKeyDown, I know come up with another error:  "Error reading Clients.OnKeyDown: Invalid value for property".  I have searched and cannot find the assignment/use of "Clients.OnKeyDown"...

I am trying to use the RET -> TAB function to make the input of all of the data more "User-friendly."  Then, I intend to incorporate the GoodKeys routine to error-check the users' inputs.  Utilizing the properties provided by the IDE, I wouldn't think I would need to code the routine into each TEdit, just make a call to the procedure as I am trying to do with the OnKeyDown event.

Clicking to write code...a big learning curve...  I ordered the Lazarus The Complete Guide the other day, but it'll be a while before it gets here...  Sorry for you guys.   :(

Awaiting for your imparted knowledge.

Thank you, in advance, for your time and assistance!

Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Changing TEdit to an integer
« Reply #37 on: November 23, 2013, 09:27:07 pm »
It doesn't work that way.  Select the Form - go to the property editor and find 'KeyPreview' and set it to True.  Now go to the events and select 'OnKeyDown' and write that code in the 'OnKeyDown' event for the Form.  But you may find that causes some problems, maybe not.  You may have to do some checks to see what kind of control has the focus.
Lazarus Trunk / fpc 2.6.2 / Win32

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Changing TEdit to an integer
« Reply #38 on: November 24, 2013, 12:28:38 am »
As well as renaming the procedure you missed off the third parameter (...; Shift: TShiftState);
That is the reason for the incompatibility error.
Provided the signature of the parameters in an OnKeyDown procedure matches that of TKeyEvent it will be assignment-compatible with any other TKeyEvent handler, whatever its name.

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: Changing TEdit to an integer
« Reply #39 on: November 24, 2013, 12:43:04 am »
It works!!  (But you guys knew that.)

Avishai & engkin - I forgot about the KeyPreview property.
howardpc - I spent a lot of time on the post.  I had already gone back into the code a few times and I had already added the shift key parameter.  Guess I should have reread the code as well as my verbiage.  Thanks for catching it.

Thank you all for your help!!
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

 

TinyPortal © 2005-2018