Inno Setup: How to run a code procedure in Run sec

2019-02-14 22:35发布

I want to remove the old database before installing the new one, to update it for the user.

I have the following scenario:

In my Components section I have an option for the user:

[Components]
Name: "updateDatabase";  Description: "Update Database";  Types: custom; \
    Flags: checkablealone disablenouninstallwarning

And I have in Code section, a procedure to execute, if the user selects this option, in the run section, before installing the new one.

[Code]
procedure RemoveOldDatabase();
begin
...
end;

[Run]
**--> Here I want to call RemoveOldDatabase if Components: updateDatabase is checked**
Filename: "database.exe"; StatusMsg: "Installing new database..."; Components: updateDatabase

The installation of the new database works fine. The problem is I want to remove the old one before installing the new one, calling the procedure RemoveOldDatabase.

Is it possible by only using Inno Setup?

Thanks.

标签: inno-setup
1条回答
Deceive 欺骗
2楼-- · 2019-02-14 23:08

One way, in my view really simple and still descriptive, is to execute your procedure as a BeforeInstall parameter function of your [Run] section entry. A BeforeInstall parameter function is executed once right before an entry is processed (and only if it's processed, which in your case is when the component is selected). You would write just this:

[Run]
Filename: "database.exe"; Components: UpdateDatabase; BeforeInstall: RemoveOldDatabase

[Code]
procedure RemoveOldDatabase;
begin
  { ... }
end;
查看更多
登录 后发表回答