Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi组件安装实用程序控制台应用程序_Delphi_Registry_Components_Installation_Delphi 7 - Fatal编程技术网

Delphi组件安装实用程序控制台应用程序

Delphi组件安装实用程序控制台应用程序,delphi,registry,components,installation,delphi-7,Delphi,Registry,Components,Installation,Delphi 7,我被难倒了。 我正在为Smart Install Maker编写一个安装支持插件,它将为我安装一些组件-AlphaControls:) 该插件是一个控制台应用程序。但是出于某种原因[在代码中]为了将包添加到“已知包”注册表位置,它希望添加一个额外的注册表项,即使数组大小仅设置为3。它试图添加一个.DPK文件,即使数组是为.BPL设置的。苏。。。我勒个去???? 除了最后一个它试图添加的唠叨点之外,它一切都正常。 编译大小约为97/98k,经过优化和压缩后缩小到48k左右 所以我想我的问题是,有人

我被难倒了。 我正在为Smart Install Maker编写一个安装支持插件,它将为我安装一些组件-AlphaControls:)

该插件是一个控制台应用程序。但是出于某种原因[在代码中]为了将包添加到“已知包”注册表位置,它希望添加一个额外的注册表项,即使数组大小仅设置为3。它试图添加一个.DPK文件,即使数组是为.BPL设置的。苏。。。我勒个去???? 除了最后一个它试图添加的唠叨点之外,它一切都正常。 编译大小约为97/98k,经过优化和压缩后缩小到48k左右

所以我想我的问题是,有人能发现我似乎忽略的错误吗? 是的,我知道-INNO设置,但是。。。我已经把钱花在Smart Install Maker上了,所以我必须使用它。
无编译错误,justs向注册表添加额外的非.bpl文件

代码如下

{Smart Install Maker installation support for components}
{for Delphi 7.0 environment only}
program pakghlp;

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils,
  Classes,
  Registry;

var  SPath,
   BPLPath,
   IDERoot,
   DPKName: string;

const
 BaseName = 'AlphaControls';

 PackageRoot = 'AlphaControls\';

 DPKFiles: array[1..5]
  of string = ('acntD7_R.dpk',
               'acntD7.dpk',
               'aceD7_R.dpk',
               'aceD7.dpk',
               'AlphaDB7.dpk');

 DPKArraySize = 5;

 BPLFiles: array[1..3]
 of string = ('aceD7.bpl',
              'acntD7.bpl',
              'AlphaDB7.bpl');

 BPLDetails: array[1..3]
 of string = ('AlphaControls extra',
              'AlphaControls',
              'AlphaControls DB-aware pack');

 BPLFileQty = 3;

  LookFor: array[1..2] of string = ('*.dcp','*.bpl');
  LookForQty = 2;

  RegPath = ';$(DELPHI)\Components\AlphaControls';

procedure InitVariables;
var
    RegKey: TRegistry;
 TargetKey: string;
   LibPath: string;
begin
 RegKey:= TRegistry.Create;
   try
     RegKey.RootKey := HKEY_CURRENT_USER;
     TargetKey:= 'Software\Borland\Delphi\7.0';
     if RegKey.OpenKeyReadOnly(TargetKey) then
       begin
        IDERoot:= RegKey.ReadString('RootDir');
        RegKey.CloseKey;

        TargetKey:= 'Software\Borland\Delphi\7.0\Library';
        RegKey.OpenKeyReadOnly(TargetKey);
        SPath:= RegKey.ReadString('Search Path');
        LibPath:= RegKey.ReadString('Package DPL Output');
        RegKey.CloseKey;

        LibPath:= StringReplace(LibPath,'$(DELPHI)','',[rfIgnoreCase]);
        BPLPath:= IDERoot + LibPath + '\';
       end;
    finally
     RegKey.Free;
    end;
end;

procedure GetListing(const SearchFor: String; ImportList:TStringList);
var SrchResult : TSearchRec;
begin
if FindFirst(SearchFor, faAnyFile, SrchResult) = 0 then
  begin
    repeat
     ImportList.Add(SrchResult.name);
    until FindNext(SrchResult) <> 0;
    FindClose(SrchResult);
  end;
end;

procedure GetBaseNames(Listing: TStringList);
var TempList: TStringList;
           i: integer;
    BaseName: string;
begin
  TempList:= TStringList.Create;
  TempList.Delimiter:= ';';
  TempList.DelimitedText:= SPath;
  Listing.Clear;
  for i:= 0 to TempList.Count - 1 do
    begin
    BaseName:= TempList[i];
    StringReplace(BaseName,'$(DELPHI)','X:\Dummy\Folder',[rfIgnoreCase]);
    Listing.Add(ExtractFileName(BaseName));
    end;
  TempList.Free;
end;

function AlreadyExists: boolean;
var CheckList: TStringList;
            i: integer;
    Installed: boolean;
begin
  CheckList:= TStringList.Create;
  GetBaseNames(CheckList);

  for i:= 0 to CheckList.Count -1 do
   begin
     if CheckList[i] = BaseName
      then Installed:= true;
       if Installed = true then break;
     Installed:= false;
   end;
CheckList.Free;
Result:= Installed;
end;

procedure ProcessIDE(InstallType: integer);
var RegKey: TRegistry;
  TempList: TStringList;
       i,j: integer;
  NewSPath,
  RegName,
  RegValue,
  DelEntry: string;
begin
RegKey:= TRegistry.Create;
  case InstallType of

    0:  begin {-uninstall}
         TempList:= TStringList.Create;
         TempList.Delimiter:= ';';
         TempList.DelimitedText:= SPath;
         DelEntry:= copy(RegPath,2,Length(RegPath));
         for i:= 0 to TempList.Count - 1 do
          begin
            if TempList[i] = DelEntry
            then
             begin
              Templist.BeginUpdate;
              Templist.Delete(i);
              TempList.EndUpdate;
             end;
          end;
          NewSPath:= TempList.DelimitedText;
          try
            RegKey.RootKey:= HKEY_CURRENT_USER;
            RegKey.OpenKey('Software\Borland\Delphi\7.0\Library',false);
            RegKey.WriteString('Search Path',NewSPath);
            RegKey.CloseKey;

            RegKey.OpenKey('Software\Borland\Delphi\7.0\Known Packages',false);
            for i:= 0 to BPLFileQty do
              begin
                RegName:= BPLPath + BPLFiles[i];
                RegKey.DeleteValue(RegName);
              end;
          finally
            RegKey.CloseKey;
          end;
         TempList.Free;
        end;

    1:  begin {-install}
          SPath:= SPath + RegPath;
          try
            RegKey.RootKey:= HKEY_CURRENT_USER;
            RegKey.OpenKey('Software\Borland\Delphi\7.0\Library',false);
            RegKey.WriteString('Search Path',SPath);
            RegKey.CloseKey;

            RegKey.OpenKey('Software\Borland\Delphi\7.0\Known Packages',false);
            for j:= 0 to BPLFileQty do
              begin
                RegName:= BPLPath + BPLFiles[j];
                RegValue:= BPLDetails[j];
                RegKey.WriteString(RegName,RegValue);
              end;
          finally
          RegKey.CloseKey;
          end;
        end;
  end;
RegKey.Free;
end;

procedure CompilePackage(PackageName: String; Wait: Boolean);
var
  StartInfo : TStartupInfo;
  ProcInfo : TProcessInformation;
  CreateOK : Boolean;
begin
  FillChar(StartInfo,SizeOf(TStartupInfo),#0);
  FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
  StartInfo.cb := SizeOf(TStartupInfo);
  CreateOK := CreateProcess(nil, PChar(PackageName), nil, nil,False,
              CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
              nil, nil, StartInfo, ProcInfo);
  if CreateOK then
    begin
      if Wait then
        WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    end
  else
    begin
      WriteLN('Unable to compile: ' + DPKName);
     end;
  CloseHandle(ProcInfo.hProcess);
  CloseHandle(ProcInfo.hThread);
end;

procedure ProcessPackages;
var Package: string;
          i: integer;
const DCC32 = 'DCC32 ';
begin
  for i:= 1 to DPKArraySize do
  begin
    DPKName:= ExpandFileName(GetCurrentDir + '\..')
            + '\' + PackageRoot + DPKFiles[i];
    Package:= DCC32 + '"' + DPKName + '"';
    CompilePackage(Package,true);
    Sleep(500);
  end;
end;

procedure ProcessFiles(InstallType: integer);
var TempList: TStringList;
    MoveList: TextFile;
         i,j: integer;
    FileFrom,
      FileTo,
   ParentDir,
  SearchType: string;
begin
  case InstallType of

    0:  begin {-uninstall}
          AssignFile(MoveList,'pakghlp.dat');
          Reset(MoveList);
            while not eof(MoveList) do
              begin
                readLn(MoveList,FileFrom);
                if FileExists(FileFrom)
                then DeleteFile(PChar(FileFrom));
              end;
          CloseFile(MoveList);
          DeleteFile(PChar('pakghlp.dat'));
        end;

    1:  begin {-install}
        ProcessPackages;
          if FileExists('pakghlp.dat') then DeleteFile(PChar('pakghlp.dat'));
           AssignFile(MoveList,'pakghlp.dat');
           Rewrite(MoveList);
           ParentDir:= ExpandFileName(GetCurrentDir + '\..') + '\';
           TempList:= TStringList.Create;
          for i:= 1 to LookForQty do // file extension types
            begin
              SearchType:= ParentDir + PackageRoot + LookFor[i];
              GetListing(SearchType,TempList);
              for j:= 0 to Templist.Count - 1 do
                begin
                  FileFrom:= ParentDir + PackageRoot + TempList[j];
                  FileTo:= BPLPath + TempList[j];
                  CopyFile(PChar(FileFrom),PChar(FileTo),False);
                  DeleteFile(PChar(FileFrom));
                  WriteLn(MoveList,FileTo);
                end;
            end;
          CloseFile(MoveList);
        end;
  end;
TempList.Free;
end;

procedure InstallComponents;
begin
  InitVariables;
  if AlreadyExists then ProcessFiles(1) // refresh corrupt .dcu's.
  else
    begin // didn't previously exist
      ProcessFiles(1);
      ProcessIDE(1);
    end;
end;

procedure RemoveComponents;
begin
  InitVariables;
  ProcessFiles(0);
  ProcessIDE(0);
end;

{ ----- Console Application Begins Here ------- }
begin
  if ParamCount =  0 then exit;

  if ParamStr(1) = '-install'
    then InstallComponents;

  if ParamStr(1) = '-uninstall'
    then RemoveComponents

  else exit; // garbage trap
end.
{组件的智能安装生成器安装支持}
{仅适用于Delphi 7.0环境}
pakghlp计划;
{$APPTYPE控制台}
使用
窗户,
SysUtils,
班级,
登记处;
var SPath,
BPLPath,
IDERoot,
DPKName:字符串;
常数
BaseName='AlphaControls';
PackageRoot='AlphaControls\';
DPK文件:数组[1..5]
字符串的长度=('acntD7_R.dpk',
“acntD7.dpk”,
“aceD7_R.dpk”,
“aceD7.dpk”,
“AlphaDB7.dpk”);
DPKArraySize=5;
BPLFiles:数组[1..3]
字符串的长度=('aceD7.bpl',
“acntD7.bpl”,
“AlphaDB7.bpl”);
BPL详细信息:数组[1..3]
字符串的值=('AlphaControls extra',
“字母控制”,
“AlphaControls DB感知包”);
BPLFileQty=3;
查找:字符串=('*.dcp','*.bpl')的数组[1..2];
LookForQty=2;
RegPath='$(DELPHI)\Components\AlphaControls';
程序变量;
变量
雷基:树木学;
TargetKey:字符串;
LibPath:string;
开始
RegKey:=TRegistry.Create;
尝试
RegKey.RootKey:=HKEY\U当前用户;
TargetKey:=“软件\Borland\Delphi\7.0”;
如果RegKey.OpenKeyReadOnly(TargetKey),则
开始
IDERoot:=RegKey.ReadString('RootDir');
RegKey.CloseKey;
TargetKey:=“软件\Borland\Delphi\7.0\Library”;
RegKey.OpenKeyReadOnly(TargetKey);
SPath:=RegKey.ReadString('Search Path');
LibPath:=RegKey.ReadString('Package DPL Output');
RegKey.CloseKey;
LibPath:=StringReplace(LibPath,$(DELPHI),,[rfIgnoreCase]);
BPLPath:=IDERoot+LibPath+'\';
结束;
最后
RegKey.Free;
结束;
结束;
过程GetListing(const SearchFor:String;ImportList:TStringList);
var SrchResult:TSearchRec;
开始
如果FindFirst(SearchFor、faAnyFile、SrchResult)=0,则
开始
重复
ImportList.Add(SrchResult.name);
直到FindNext(SrchResult)0;
FindClose(SrchResult);
结束;
结束;
过程GetBaseNames(清单:TStringList);
var TempList:TStringList;
i:整数;
BaseName:字符串;
开始
圣堂武士:=TStringList.Create;
分隔符:=';';
templast.DelimitedText:=SPath;
列表。清除;
对于i:=0到templast.Count-1 do
开始
BaseName:=圣堂武士[i];
StringReplace(BaseName,$(DELPHI),'X:\Dummy\Folder',[rfIgnoreCase]);
Add(ExtractFileName(BaseName));
结束;
圣殿骑士,自由;
结束;
函数AlreadyExists:布尔;
var检查表:TStringList;
i:整数;
已安装:布尔值;
开始
检查表:=TStringList.Create;
GetBaseNames(检查表);
对于i:=0到检查表。计数-1 do
开始
如果检查表[i]=基本名称
然后安装:=true;
如果安装=真,则断开;
已安装:=错误;
结束;
清单。免费;
结果:=已安装;
结束;
过程ProcessIDE(InstallType:integer);
var RegKey:树木学;
圣殿骑士:TStringList;
i、 j:整数;
新闻路径,
RegName,
RegValue,
去中心:字符串;
开始
RegKey:=TRegistry.Create;
案例类型
0:开始{-uninstall}
圣堂武士:=TStringList.Create;
分隔符:=';';
templast.DelimitedText:=SPath;
DelEntry:=复制(RegPath,2,长度(RegPath));
对于i:=0到templast.Count-1 do
开始
如果圣堂武士[i]=DelEntry
然后
开始
templast.BeginUpdate;
删除(i);
templast.EndUpdate;
结束;
结束;
新闻路径:=templast.DelimitedText;
尝试
RegKey.RootKey:=HKEY\U当前用户;
OpenKey('Software\Borland\Delphi\7.0\Library',false);
RegKey.WriteString('搜索路径',新闻路径);
RegKey.CloseKey;
RegKey.OpenKey('Software\Borland\Delphi\7.0\Known Packages',false);
对于i:=0到BPLFileQty do
开始
RegName:=BPLPath+BPLFiles[i];
RegKey.DeleteValue(RegName);
结束;
最后
RegKey.CloseKey;
结束;
圣殿骑士,自由;
结束;
1:开始{-install}
SPath:=SPath+RegPath;
尝试
RegKey.RootKey:=HKEY\U当前用户;
OpenKey('Software\Borland\Delphi\7.0\Library',false);
RegKey.WriteString('Search Path',SPath);
RegKey.CloseKey;
RegKey.OpenKey('Software\Borland\Delphi\7.0\Known Packages',false);
对于j:=0到BPLFileQty do
开始
RegName:=BPLPath+BPLFiles[j];
RegValue:=BPLDetails[j];
RegKey.WriteString(RegName,RegValue);
结束;
最后
RegKey.CloseKey;
结束;
结束;
结束;
RegKey.Free;
结束;
过程编译包(PackageName:String;Wait:Boolean);
变量
StartInfo:TStartupInfo;
ProcInfo:TProcessInformation;
CreateOK:布尔;
开始
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,Siz
const
     BPLFiles: array[1..3]
     of string = ('aceD7.bpl',
                  'acntD7.bpl',
                  'AlphaDB7.bpl');
for i:= 0 to BPLFileQty do
    begin
      RegName:= BPLPath + BPLFiles[i];
      RegKey.DeleteValue(RegName);
    end;
for i:= 1 to BPLFileQty do
    begin
      RegName:= BPLPath + BPLFiles[i];
      RegKey.DeleteValue(RegName);
    end;
        for j:= 0 to BPLFileQty do
          begin
            RegName:= BPLPath + BPLFiles[j];
            RegValue:= BPLDetails[j];
            RegKey.WriteString(RegName,RegValue);
          end;
        for j:= 1 to BPLFileQty do
          begin
            RegName:= BPLPath + BPLFiles[j];
            RegValue:= BPLDetails[j];
            RegKey.WriteString(RegName,RegValue);
          end;