Recent

Author Topic: Process at application-start [SOLVED]  (Read 240 times)

AlphaInc.

  • New Member
  • *
  • Posts: 13
Process at application-start [SOLVED]
« on: September 16, 2020, 05:10:40 pm »
Hello everybody,

I want to implement a start-up process that, whenever the application get’s started, it checks for either a string in a file or a file itself, depends on what is easier to implement. If the string (or the file) is found then i want a button-caption to be set to On (for example) and if it’s not found than the Caption should be set to Off.
Either way, i don’t have the full path. I would like the application to look in the current directory (for example, in cmd it would be &CD&\folder1\file.ext

Unfortunately, I’m a total noob when it comes to developing and programming so i hope someone has the time to help me. 
« Last Edit: September 17, 2020, 12:06:32 am by AlphaInc. »

jamie

  • Hero Member
  • *****
  • Posts: 3538
Re: Process at application-start
« Reply #1 on: September 16, 2020, 10:42:25 pm »
AButton.Enabled := FileExists('Your local file name');

Edit:

Or

Const Names:Array[Boolean] of String =('No', 'yes');

-------

 MyButton.Caption := names(FileExists('your Local File Name'));


« Last Edit: September 16, 2020, 10:56:06 pm by jamie »
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 3912
    • Bart en Mariska's Webstek
Re: Process at application-start
« Reply #2 on: September 16, 2020, 11:09:35 pm »
Assuming you are talking about a Lazarus application (you talk about a Button), you can put such code in the main forms OnCreate event.
Just double click on the form and an OnCreate event will be created for you.

Code: [Select]
procedure TForm1Create(Sender: TObject);
begin
  if FileExists('.\myfilename.extension') then
    Button1.Caption := 'Ok'
  else
    Button1.Caption := 'Not Ok';
end;

By starting the filename with '.\' the function FileExists will look for that file in the current directory (to be specific the directory from which the program was started, which can be different from the place where the application resides).

Bart

AlphaInc.

  • New Member
  • *
  • Posts: 13
Re: Process at application-start
« Reply #3 on: September 17, 2020, 12:05:48 am »
Thank you Bart, that was what I'm looking for.  ::)

 

TinyPortal © 2005-2018