2015-11-05 54 views
1

我想提供幾種不同的安裝類型,對我的安裝程序執行不同的操作:如果選擇「ApplicationServer」類型,則只執行部分代碼。如果選擇客戶端類型,則只執行這部分過程。Inno Setup根據安裝類型運行代碼

我試圖包括一個被調用的函數內的代碼2「塊」

[Types] 
Name: "application"; Description: "{cm:ApplicationServer}" 
Name: "client"; Description: "{cm:Client}" 

[CustomMessages] 
ApplicationServer=Application Server: 
Client=Client: 

如果選擇的第一選擇,我想執行由若干程序,常數,變量運行的特定代碼SQL腳本的序列,而如果選擇第二我需要執行一些其他東西進入代碼區,像這樣:

[Code] 

function ApplicationServer(blabla) 
begin: 
    { <!This part only to run for ApplicationServer type!> } 
    { following constants and variables for the ADO Connection + SQL script run } 
    const 
    myconstant1=blabla; 
    var 
    myvar1=blabla;  
    { here all the procedure to define and manage an ADO Connection to run a sql script } 
    { procedure 1 } 
    { procedure 2 } 
end 

function Client(blabla) 
begin: 
    { <!This part only to run for Client type!> } 
    { following constants and variables only for performing some stuffs on top of client } 
    const 
    myconstant2=blabla; 
    var 
    myvar2=blabla; 
    { procedure 3 } 
    { procedure 4 } 
end 

有管理的代碼的特定部分,根據類型運行方式的安裝運行?

謝謝。

回答

1

使用WizardSetupType support function

您可能需要檢查CurStepChangedevent function

procedure ApplicationServer; 
begin 
    { procedure 1 } 
    { procedure 2 } 
end; 

procedure Client; 
begin 
    { procedure 1 } 
    { procedure 2 } 
end; 

procedure CurStepChanged(CurStep: TSetupStep); 
var 
    SetupType: string; 
begin 
    Log(Format('CurStepChanged %d', [CurStep])); 

    if CurStep = ssInstall then 
    begin 
    SetupType := WizardSetupType(False); 

    if SetupType = 'application' then 
    begin 
     Log('Installing application server'); 
     ApplicationServer; 
    end 
     else 
    if SetupType = 'client' then 
    begin 
     Log('Installing client'); 
     Client; 
    end 
     else 
    begin 
     Log('Unexpected setup type: ' + SetupType); 
    end; 
    end; 
end; 

帕斯卡腳本不支持本地常量,只有全局常量。

不管怎麼說,如果你想要一個局部常量或者有條件地初始化一個全局常量,你想要什麼。無論如何,你不能做後者,常數不變,它不能有不同的值。

與你的變量一樣。 這些局部變量還是您想要有條件地將值設置爲全局變量?

+0

感謝您的建議! [code]部分中定義的常量和變量僅用於運行sql腳本(即,僅用於「應用程序服務器」類型)。因此,在您建議的腳本之前,可能需要將它們全部定義爲全局。 什麼是不明確,因爲我沒有抓住很多例子是如何使用上面提到的WizardSetupType函數。 您能否提供更多關於此的更多細節? – Luca

+0

我的不好:我忘記了。我道歉。 – Luca

+0

到目前爲止,我通過將另一部分代碼嵌入到另一個inno腳本中找到了一種替代方法:只要應用程序類型在主腳本上運行,就會調用此方法。再次感謝您的建議馬丁 – Luca