Recent

Author Topic: Take value from input box and use it as bat parameter  (Read 2406 times)

totalnooob

  • Newbie
  • Posts: 5
Take value from input box and use it as bat parameter
« on: May 10, 2019, 02:35:40 pm »
Hi guys
Im making small app with lazarus with one input box and button a i need to take value from text box an put it as parameter in command how do i do that ? my programming skills are pretty bad. Sorry
Thanks

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, process, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
  9.   var   RunProgram: TProcess;
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Edit1: TEdit;
  17.     Image1: TImage;
  18.     Label1: TLabel;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure Edit1Change(Sender: TObject);
  21.     procedure Image1Click(Sender: TObject);
  22.     procedure Label1Click(Sender: TObject);
  23.   private
  24.  
  25.   public
  26.  
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.Label1Click(Sender: TObject);
  39. begin
  40.  
  41. end;
  42.  
  43. procedure TForm1.Edit1Change(Sender: TObject);
  44. begin
  45.  
  46. end;
  47.  
  48.  
  49. procedure TForm1.Button1Click(Sender: TObject);
  50. begin
  51.    RunProgram := TProcess.Create(nil);
  52.    RunProgram.CommandLine := 'start.bat parameter1';
  53.    RunProgram.Execute;   RunProgram.Free;
  54.  
  55.  
  56. end;
  57.  
  58. procedure TForm1.Image1Click(Sender: TObject);
  59. begin
  60.  
  61. end;
  62.  
  63. end.          

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Take value from input box and use it as bat parameter
« Reply #1 on: May 10, 2019, 03:22:24 pm »
Hello totalnoob,
Welcome to the forum.

You can do it like this:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, process, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   ExtCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Edit1: TEdit;
  18.     Image1: TImage;
  19.     Label1: TLabel;
  20.     procedure Button1Click(Sender: TObject);
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. var
  34.   RunProgram: TProcess;
  35. begin
  36.    RunProgram := TProcess.Create(nil);
  37.    RunProgram.Executable:= 'start.bat';
  38.    RunProgram.Parameters.Add(Edit1.Text);
  39.    RunProgram.Options := RunProgram.Options + [poWaitOnExit];
  40.    RunProgram.Execute;
  41.    RunProgram.Free;
  42. end;
  43.  
  44. end.

If you want to learn more about TProcess, read here:
http://wiki.freepascal.org/Executing_External_Programs#TProcess

totalnooob

  • Newbie
  • Posts: 5
Re: Take value from input box and use it as bat parameter
« Reply #2 on: May 10, 2019, 04:31:27 pm »
Thanks it works fine

totalnooob

  • Newbie
  • Posts: 5
Re: Take value from input box and use it as bat parameter
« Reply #3 on: May 13, 2019, 04:41:35 pm »
Is it possible to make the app full screen without user to have ability to close it? And is it possible to when some text is added to field automaticly submit the form?

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Take value from input box and use it as bat parameter
« Reply #4 on: May 13, 2019, 05:19:22 pm »
Is it possible to make the app full screen without user to have ability to close it?

Short answer: yes

Long answer:
Don't do it, it is bad for user experience. I ever got uncloseable programs, I hate it ... I deleted them immediately, it's super annoying. If you play computer games, you know most of them are run in full screen mode, without title bar and the close button on the corner. Even without the close button, user still can 'force' it to close using Task Manager. But you still can make it uncloseable. If pay attention on the antivirus installed in your PC, you will notice most of them are not able to fully close even you 'end task' it on your Task Manager. I haven't tried but I believe they can achieve it by starting some additional programs (as services) and keep monitor if one of them is closed, so they will start it again on memory automatically.

And is it possible to when some text is added to field automaticly submit the form?

Yes, it is easy. Usually you put something like this below in the form's OnCreate event:
Edit1.Text := 'the text you want to put';
« Last Edit: May 13, 2019, 05:29:27 pm by Handoko »

totalnooob

  • Newbie
  • Posts: 5
Re: Take value from input box and use it as bat parameter
« Reply #5 on: May 14, 2019, 11:29:00 am »
Hi need to create kiosk style program which users cannot close i would disable ability to open task manager, user will scan his rfid card. It will automaticly login into their account associated with rfid card through script

Imants

  • Full Member
  • ***
  • Posts: 196
Re: Take value from input box and use it as bat parameter
« Reply #6 on: May 14, 2019, 01:15:44 pm »
Hi need to create kiosk style program which users cannot close i would disable ability to open task manager, user will scan his rfid card. It will automaticly login into their account associated with rfid card through script

If you disabled task manager.
Then you can set form BorderStyle = bsNone, WindowState = wsMaximized and FormStyle = fsStayOnTop
and then assign OnCloseQuery to something like this:

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
  CanClose := False;
end; 

And your form will be pretty unclosable. I tired using alt+f4 and close option from windows task bar and application newer closed.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Take value from input box and use it as bat parameter
« Reply #7 on: May 14, 2019, 01:33:00 pm »
[...] Then you can set form BorderStyle = bsNone, WindowState = wsMaximized and FormStyle = fsStayOnTop [...]

Instead of wsMaximized, set WindowState = wsFullScreen: that way the user won't see (and be able to access) the taskbar(s).

And rather than fsStayOntop, set FormStyle = fsSystemStayOnTop so that only ultra-high priority system messages can pop over your app.

Note that all this means that application should monitor and process all exceptions and errors, even system ones, unless you want it to appear in one of those funny photos captioned as: "Look this! Airport terminal tells me my card number is 'Error: 0x76D456' at line 6540' ROFL!!!" :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Take value from input box and use it as bat parameter
« Reply #8 on: May 15, 2019, 12:27:44 am »
Instead of wsMaximized, set WindowState = wsFullScreen: that way the user won't see (and be able to access) the taskbar(s).
In Windows wsFullScreen does not process correctly (example bug 34759). Don't use it. With wsMaximized and fsStayOntop the taskbar is hidden.
Quote
And rather than fsStayOntop, set FormStyle = fsSystemStayOnTop so that only ultra-high priority system messages can pop over your app.
You will also need to enable system policies that prohibit system hotkeys.

totalnooob

  • Newbie
  • Posts: 5
Re: Take value from input box and use it as bat parameter
« Reply #9 on: May 20, 2019, 10:49:53 am »
would it be possible to only accept the 9 digit number code from rfid card in the text field? So if the user put anything else as input other than the numbers the script wont start. Or maybe i would hide the enter button and it will automaticly trigger when it detect the rfid card or hide the entire input field a it will be all in background?
What would you suggest?
Thanks

BorderStyle = bsNone, WindowState = wsMaximized and FormStyle = fsStayOnTop works fine just need to block ALT+F4 somehow
« Last Edit: May 20, 2019, 10:53:05 am by totalnooob »

Imants

  • Full Member
  • ***
  • Posts: 196
Re: Take value from input box and use it as bat parameter
« Reply #10 on: May 20, 2019, 03:48:23 pm »
would it be possible to only accept the 9 digit number code from rfid card in the text field? So if the user put anything else as input other than the numbers the script wont start. Or maybe i would hide the enter button and it will automaticly trigger when it detect the rfid card or hide the entire input field a it will be all in background?
What would you suggest?
Thanks

BorderStyle = bsNone, WindowState = wsMaximized and FormStyle = fsStayOnTop works fine just need to block ALT+F4 somehow

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
  CanClose := False;
end; 

Blocks Alt+F4

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Take value from input box and use it as bat parameter
« Reply #11 on: May 20, 2019, 08:23:24 pm »
would it be possible to only accept the 9 digit number code from rfid card in the text field?

Yes: use a TMaskEdit control instead of a TEdit, setting its EditMask to '000000000'. The control will accept exactly nine digits, nothing else.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018