Results 1 to 7 of 7

Thread: How do I make it so that only integers can go into a Tedit box?

  1. #1
    Join Date
    Jul 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How do I make it so that only integers can go into a Tedit box?

    The topic says it all, does anyone know how I can make it so that I can only make certain text go into an edit box? Say I wanted only wanted integers in one, how can I do this?

    - Barrier

  2. #2
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    I don't think there's a command to do that in SCAR, but you could do this:

    SCAR Code:
    Edit1.OnChange := @StripLetters;...

    procedure StripLetters(Sender: TObject);
    var
      Numbers: String;
      i: integer;
    begin
      Numbers := '0123456789';
      for i := 1 to Length(Edit1.Text) - 1 do
        if(Pos(Edit1.Text[i], Numbers) = 0)then
          Delete(Edit1.Text, i, 1);
    end;

    Or something like that....
    Interested in C# and Electrical Engineering? This might interest you.

  3. #3
    Join Date
    Jul 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Smartzkid View Post
    I don't think there's a command to do that in SCAR, but you could do this:

    SCAR Code:
    Edit1.OnChange := @StripLetters;...

    procedure StripLetters(Sender: TObject);
    var
      Numbers: String;
      i: integer;
    begin
      Numbers := '0123456789';
      for i := 1 to Length(Edit1.Text) - 1 do
        if(Pos(Edit1.Text[i], Numbers) = 0)then
          Delete(Edit1.Text, i, 1);
    end;

    Or something like that....
    Thank you! It says that a variable is expected in the script though...

  4. #4
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    but to be honest , the form will really only return strings

  5. #5
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    then you just strtoint.

  6. #6
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Yes but trying to do that with a value of say 'k' will result in a error meaning that it cant evenn be checked but u could use that as validateion

  7. #7
    Join Date
    May 2006
    Posts
    1,230
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    program New;
    var
      frmDesign : TForm;
      Label1 : TLabel;
      Edit1 : TEdit;

    procedure Block2(Sender: TObject; var Key: Char);
    var
      numbers : string;
    begin
      numbers := '0123456789' + chr(8);
      if pos(key, numbers) = 0 then
      begin
        Label1.Caption := 'Blocked you from typing ' + key;
        Key := Chr(13); //changes key to enter, makes beep plus blocks it. Chr(0) can work too
      end;
    end;

    procedure Init;
    begin
      frmDesign := CreateForm;
      frmDesign.SetBounds(250, 114, 230, 68);
      frmDesign.Caption := 'frmDesign';
      Label1 := TLabel.Create(frmDesign);
      Label1.Parent := frmDesign;
      Label1.SetBounds(2, 2, 217, 13);
      Edit1 := TEdit.Create(frmDesign);
      Edit1.Parent := frmDesign;
      Edit1.SetBounds(1, 19, 219, 21);
      Edit1.OnKeyPress := @Block2;
      frmDesign.ShowModal
    end;

    procedure Safe;
    var
      p : TVariantArray;
    begin
      ThreadSafeCall('Init', p);
    end;

    begin
      Safe;
    end.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Integers in TIntegerArray
    By marpis in forum OSR Help
    Replies: 12
    Last Post: 03-03-2009, 11:19 PM
  2. Integers
    By Jackrawl in forum OSR Help
    Replies: 16
    Last Post: 12-23-2007, 03:55 PM
  3. integers!
    By Cruel100 in forum OSR Help
    Replies: 7
    Last Post: 10-27-2007, 04:28 PM
  4. Help with Multiplying integers...
    By snuwoods in forum OSR Help
    Replies: 5
    Last Post: 02-07-2007, 12:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •