inno setup编译报错:line 69 Identifier expected

jhams 2016-04-07 10:33:35
下面是代码:
if bInsForAllUser then
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue);
else //69行,这里报错
begin
if (not aIsInstall) and (Trim(sOrgValue) = '') then
RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName);
else
RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue);
end;

完整代码在下面:

#define MyAppName "drug2"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "GxSingleCamColor.exe"
#define MyAppExe64Name "MER_USB_Setup64cn.exe"
#define MyAppExe32Name "MER_USB_Setup32cn.exe"
#define MyAppExefreetype "freetype-2.3.5-1-setup.exe"
#define MyAppExeopencv "opencv-2.4.9.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{C33AD2D6-612C-48E4-8860-259DD66349EF}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
ChangesEnvironment=yes

[Code]
procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall, aIsInsForAllUser: Boolean);//设置环境变量函数
var
sOrgValue: string;
S1, sFileName, sInsFlag: string;
bRetValue, bInsForAllUser: Boolean;
SL: TStringList;
x: integer;
begin
bInsForAllUser := aIsInsForAllUser;
if UsingWinNT then
begin
if bInsForAllUser then
bRetValue := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue)
else
bRetValue := RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue);
sOrgValue := Trim(sOrgValue);
begin
S1 := aEnvValue;
if pos(Uppercase(sOrgValue), Uppercase(s1)) = 0 then //还没有加入
begin
if aIsInstall then
begin
x := Length(sOrgValue);
if (x > 0) and (StringOfChar(sOrgValue[x], 1) <> ';') then
sOrgValue := sOrgValue + ';';
sOrgValue := sOrgValue + S1;
end;
end else
begin
if not aIsInstall then
begin
StringChangeEx(sOrgValue, S1 + ';', '', True);
StringChangeEx(sOrgValue, S1, '', True);
end;
end;
if bInsForAllUser then
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue);
else //69行,这里报错
begin
if (not aIsInstall) and (Trim(sOrgValue) = '') then
RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName);
else
RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue);
end;
end;
end else //非NT 系统,如Win98
begin
SL := TStringList.Create;
try
sFileName := ExpandConstant('{sd}/autoexec.bat');
LoadStringFromFile(sFileName, S1);
SL.Text := s1;
s1 := '"' + aEnvValue + '"';
s1 := 'set '+aEnvName +'=%path%;' + s1 ;
bRetValue := False;
x := SL.IndexOf(s1);
if x = -1 then
begin
if aIsInstall then
begin
SL.Add(s1);
bRetValue := True;
end;
end else //还没添加
if not aIsInstall then
begin
SL.Delete(x);
bRetValue := True;

end;
if bRetValue then
SL.SaveToFile(sFileName);
finally
SL.free;
end;
end;

procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量
begin
if CurStep = ssPostInstall then
begin
SetEnv('path',ExpandConstant('{app}/Package/bpl;{app}/bin'),true,true); //在这儿调用,一定在这儿调用,安装完无须重启,立即生效
//SetEnv('path','{app}/bin',true,true);
end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);//删除环境变量
begin
SetEnv('path',ExpandConstant('{app}/Package/bpl;{app}/bin'),false,true);
//SetEnv('path','{app}/bin',false,true);
end;
...全文
499 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量 这没问题。 是 finally SL.free; end; // 这里少了一行 end; end;
jhams 2016-04-11
  • 打赏
  • 举报
回复
引用 10 楼 DelphiGuy 的回复:
[quote=引用 9 楼 jhams 的回复:] [quote=引用 8 楼 DelphiGuy 的回复:] [quote=引用 6 楼 jhams 的回复:] [quote=引用 2 楼 DelphiGuy 的回复:] if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue); else //69行,这里报错 begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName); else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end;
是分号的问题么[/quote] right [/quote] 这个分号是英文的啊,而且在代码里也是和语句在同一行的,有什么问题么[/quote] 我的天呐,你难道没有看到那两个分号是多余的,导致语法错误了么。 [/quote] 这个语言没用过,不懂啊,把分号去掉了,现在又报错误:: Line 82: Column 40: Type mismatch. 就是这句:LoadStringFromFile(sFileName, S1); 应该怎么改呢
jhams 2016-04-11
  • 打赏
  • 举报
回复
引用 14 楼 DelphiGuy 的回复:
这句:procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量 应该没有问题呀。
我在inno setup下面编译报错,要不你帮忙把代码拷下来编译下试试,代码如下: procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall, aIsInsForAllUser: Boolean);//设置环境变量函数 var sOrgValue: string; S1, sFileName, sInsFlag: string; SA: AnsiString;//zj bRetValue, bInsForAllUser: Boolean; SL: TStringList; x: integer; begin bInsForAllUser := aIsInsForAllUser; if UsingWinNT then begin if bInsForAllUser then bRetValue := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue) else bRetValue := RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); sOrgValue := Trim(sOrgValue); begin S1 := aEnvValue; if pos(Uppercase(sOrgValue), Uppercase(s1)) = 0 then //还没有加入 begin if aIsInstall then begin x := Length(sOrgValue); if (x > 0) and (StringOfChar(sOrgValue[x], 1) <> ';') then sOrgValue := sOrgValue + ';'; sOrgValue := sOrgValue + S1; end; end else begin if not aIsInstall then begin StringChangeEx(sOrgValue, S1 + ';', '', True); StringChangeEx(sOrgValue, S1, '', True); end; end; if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue) else begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName) else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end; end; end else //非NT 系统,如Win98 begin SL := TStringList.Create; try sFileName := ExpandConstant('{sd}/autoexec.bat'); LoadStringFromFile(sFileName, SA); //zj S1 := SA; // zj SL.Text := s1; s1 := '"' + aEnvValue + '"'; s1 := 'set '+aEnvName +'=%path%;' + s1 ; bRetValue := False; x := SL.IndexOf(s1); if x = -1 then begin if aIsInstall then begin SL.Add(s1); bRetValue := True; end; end else //还没添加 if not aIsInstall then begin SL.Delete(x); bRetValue := True; end; if bRetValue then SL.SaveToFile(sFileName); finally SL.free; end; end; procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量 begin if CurStep = ssPostInstall then begin SetEnv('path',ExpandConstant('{app}/Package/bpl;{app}/bin'),true,true); //在这儿调用,一定在这儿调用,安装完无须重启,立即生效 //SetEnv('path','{app}/bin',true,true); end; end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);//删除环境变量 begin SetEnv('path',ExpandConstant('{app}/Package/bpl;{app}/bin'),false,true); //SetEnv('path','{app}/bin',false,true); end;
  • 打赏
  • 举报
回复
这句:procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量 应该没有问题呀。
jhams 2016-04-11
  • 打赏
  • 举报
回复
引用 12 楼 DelphiGuy 的回复:
在这下面增加一个变量: var sOrgValue: string; S1, sFileName, sInsFlag: string; SA: AnsiString; 然后这里: LoadStringFromFile(sFileName, SA); S1 := SA; SL.Text := s1;
这个改过来了,现在报错误: Column 1: Identifier expected. 是这句:procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量 怎么改呢
  • 打赏
  • 举报
回复
在这下面增加一个变量: var sOrgValue: string; S1, sFileName, sInsFlag: string; SA: AnsiString; 然后这里: LoadStringFromFile(sFileName, SA); S1 := SA; SL.Text := s1;
业余草 2016-04-07
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
引用 9 楼 jhams 的回复:
[quote=引用 8 楼 DelphiGuy 的回复:] [quote=引用 6 楼 jhams 的回复:] [quote=引用 2 楼 DelphiGuy 的回复:] if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue); else //69行,这里报错 begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName); else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end;
是分号的问题么[/quote] right [/quote] 这个分号是英文的啊,而且在代码里也是和语句在同一行的,有什么问题么[/quote] 我的天呐,你难道没有看到那两个分号是多余的,导致语法错误了么。
jhams 2016-04-07
  • 打赏
  • 举报
回复
引用 8 楼 DelphiGuy 的回复:
[quote=引用 6 楼 jhams 的回复:] [quote=引用 2 楼 DelphiGuy 的回复:] if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue); else //69行,这里报错 begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName); else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end;
是分号的问题么[/quote] right [/quote] 这个分号是英文的啊,而且在代码里也是和语句在同一行的,有什么问题么
  • 打赏
  • 举报
回复
引用 6 楼 jhams 的回复:
[quote=引用 2 楼 DelphiGuy 的回复:] if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue); else //69行,这里报错 begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName); else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end;
是分号的问题么[/quote] right
业余草 2016-04-07
  • 打赏
  • 举报
回复
jhams 2016-04-07
  • 打赏
  • 举报
回复
引用 2 楼 DelphiGuy 的回复:
if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue); else //69行,这里报错 begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName); else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end;
是分号的问题么
jhams 2016-04-07
  • 打赏
  • 举报
回复
引用 4 楼 xmt1139057136 的回复:
不知道你要做什么?开机自启动还是??
是做添加path环境变量的功能
业余草 2016-04-07
  • 打赏
  • 举报
回复
不知道你要做什么?开机自启动还是??
  • 打赏
  • 举报
回复
if bInsForAllUser then RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM/CurrentControlSet/Control/Session Manager/Environment', aEnvName, sOrgValue); else //69行,这里报错 begin if (not aIsInstall) and (Trim(sOrgValue) = '') then RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName); else RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue); end;
jhams 2016-04-07
  • 打赏
  • 举报
回复
引用 1 楼 xmt1139057136 的回复:
版主帮看看啊

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧