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


  • Newbie
  • Posts: 4
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. »


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



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


  • Hero Member
  • *****
  • Posts: 3899
    • 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);
  if FileExists('.\myfilename.extension') then
    Button1.Caption := 'Ok'
    Button1.Caption := 'Not Ok';

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).



  • Newbie
  • Posts: 4
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