[Lazarus] Still some problems with PackageEditingInterface.DoOpenPackageFile

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Jan 9 16:22:09 CET 2012


On Sun, 8 Jan 2012 17:12:31 +0100
"Ludo Brands" <ludo.brands at free.fr> wrote:

> Hi,
> 
> In case I recreate a package that is already installed in lazarus,
> PackageEditingInterface.DoOpenPackageFile will bring up the package but as
> soon as I hit compile, it shows a message that the disk file has changes in
> between. 

Think about a Lazarus package like a form. The IDE has loaded its
source (lpk file) and created some structures. The IDE checks for
changes on disk and will notify the user.
If a package is already loaded the IDE will try to keep it.


> Ignoring or reloading, crashes lazarus with (ignoring in this case):
> 
> TPkgManager.DoCompilePackage A AXVLC_1_0_TLBP 0.1 Flags=[]
> [TMainIDE.Destroy] A

This means there was an unhandled/unhandable exception.
Can you give an example so I can reproduce this?
The rest are follow up bugs.

>[...]
 
> It seems installed packages are already pre-loaded 

Yes. The IDE has to load the dependencies, compiler options, etc. This
information is not compiled into the IDE, but is only stored in the lpk.


> and the window that is
> brought up with PackageEditingInterface.DoOpenPackageFile is actually a
> cached version before the overwrite. 

The IDE should try to use the cache whenever possible. But if the
package was not modified in the IDE and the lpk on disk has changed a
call DoOpenPackageFile must reload it.
Can you give an example?


> This is somewhat confirmed when I
> delete the .lpk file of an installed package as it will bring up the package
> editor for that package with the warning that the diskfile has changed. 
> 
> I'm doing now
> if PackageEditingInterface.FindPackageWithName(PkgName)<>nil then
>  
> PackageEditingInterface.DoOpenPackageFile(sDir+PkgName+'.lpk',[pofRevert],fa
> lse)
> else
>  
> PackageEditingInterface.DoOpenPackageFile(sDir+PkgName+'.lpk',[pofAddToRecen
> t],false);
> 
> but FindPackageWithName returns nil. What can I do?

If the package was modified in the IDE the IDE will keep its version
and not load the lpk from disk.
You have to pass ofRevert to ignore the user modifications and reload
the package.

When you create a new package I would recommend to use a non
existing package name. For example:

uses PackageIntf, LCLProc;

  NewPkgName:='MyPkg';
  repeat
    NewPkgName:=CreateNextIdentifier(NewPkgName);
  until PackageEditingInterface.FindPackageWithName(NewPkgName)=nil;


Mattias




More information about the Lazarus mailing list