Answer the question
In order to leave comments, you need to log in
How to open a file with your program (associate it with the program)?
I have a file that says the following
<PROJECT_SETTINGS>
<FOLDER_PATH>D:\test</FOLDER_PATH>
<ZIP_FILE_PATH>D:\arhive_test</ZIP_FILE_PATH>
</PROJECT_SETTINGS>
//Загрузить все настройки проекта из файла
procedure read_project_from_file(file_path:string);
var
current_string:string;
text_file:TextFile;
income_tags:boolean;
begin
AssignFile (text_file, file_path);
Reset (text_file);
while not EOF(text_file) do
begin
readln(text_file, current_string);
if (CountPos('<PROJECT_SETTINGS>',current_string)>0) then income_tags:=true;
if (CountPos('</PROJECT_SETTINGS>',current_string)>0) then income_tags:=false;
if (income_tags=true) then
begin
if (CountPos('<FOLDER_PATH>',current_string)>0) then folder_path:=get_stext('<FOLDER_PATH>','</FOLDER_PATH>',current_string);
if (CountPos('<ZIP_FILE_PATH>',current_string)>0) then zip_file_folder:=get_stext('<ZIP_FILE_PATH>','</ZIP_FILE_PATH>',current_string);
end;
//Заполняем форму
if (income_tags=false) then
begin
Form1.folder_path_directory_edit.Text:=folder_path;
Form1.zip_file_path_directory_edit.Text:=zip_file_folder;
end;
end;
CloseFile (text_file);
end;
procedure TForm1.open_project_buttonClick(Sender: TObject);
begin
if not OpenDialog1.Execute then Exit;
read_project_from_file(OpenDialog1.FileName);
end;
Answer the question
In order to leave comments, you need to log in
Google: "Delphi file association"
The first point answers your question.
When you have associated a file extension with a program, Windows will run your program by passing the name of the clicked file as command line options. Thus, when starting the application, you need to check for the presence of this parameter, and if it is, then call the file opening procedure.
The only thing to keep in mind is that the first parameter is always the name of your program, so look at the second parameter.
To access the parameters, there is the System.ParamStr function .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question