Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-01

Still some problems with PackageEditingInterface.DoOpenPackageFile

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ludo Brands

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.
Ignoring or reloading, crashes lazarus with (ignoring in this case):

TPkgManager.DoCompilePackage A AXVLC_1_0_TLBP 0.1 Flags=[] [TMainIDE.Destroy] A
TApplication.HandleException Access violation
Stack trace:
$00C38868 TPACKAGEEDITORS__DOFREEEDITOR, line 2400 of C:/lazarus/packager/pa
ckageeditor.pas
$00C3838D TPACKAGEEDITORFORM__DESTROY, line 2301 of C:/lazarus/packager/pack
ageeditor.pas
$0040D0C2 TOBJECT__FREE, line 278 of
C:/lazarus/fpc/svn/rtl/inc/objpas.inc
$0083E57A TLAZPACKAGEGRAPH__DELETE, line 709 of
C:/lazarus/packager/packages
ystem.pas
$0083E4FB TLAZPACKAGEGRAPH__CLEAR, line 697 of
C:/lazarus/packager/packagesy
stem.pas
$0083E441 TLAZPACKAGEGRAPH__DESTROY, line 684 of C:/lazarus/packager/package
system.pas
$0040D0C2 TOBJECT__FREE, line 278 of
C:/lazarus/fpc/svn/rtl/inc/objpas.inc
$00854D01 TPKGMANAGER__DESTROY, line 1565 of
C:/lazarus/packager/pkgmanager.
pas
$0040D0C2 TOBJECT__FREE, line 278 of
C:/lazarus/fpc/svn/rtl/inc/objpas.inc
$00449B8A TMAINIDE__DESTROY, line 1534 of main.pp $0040D0C2 TOBJECT__FREE, line 278 of
C:/lazarus/fpc/svn/rtl/inc/objpas.inc
$004272FD BEFOREFINALIZATION, line 1780 of forms.pp $0040F839 INTERNALEXIT, line 867 of
C:/lazarus/fpc/svn/rtl/inc/system.inc
$0040478C FPC_CHECK_OBJECT, line 826 of
C:/lazarus/fpc/svn/rtl/inc/generic.i
nc
$008595A8 TPKGMANAGER__DOCOMPILEPACKAGE, line 2627 of C:/lazarus/packager/pk
gmanager.pas
$00850921 TPKGMANAGER__ONPACKAGEEDITORCOMPILEPACKAGE, line 603 of C:/lazarus
/packager/pkgmanager.pas
$00C38992 TPACKAGEEDITORS__COMPILEPACKAGE, line 2427 of C:/lazarus/packager/
packageeditor.pas

It seems installed packages are already pre-loaded and the window that is brought up with PackageEditingInterface.DoOpenPackageFile is actually a cached version before the overwrite. 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?

Thanks, Ludo

Reply by email

Ludo Brands
to Ludo Brands
Show quoted text 14 lines
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?

Found the solution but it looks "sub-optimal":

if PackageEditingInterface.FindPackageWithName(TLI.UnitName+'P')nil then
  begin
PackageEditingInterface.DoOpenPackageFile(sDir+TLI.UnitName+'P.lpk',[pofReve
rt],false);
  PackageEditingInterface.DoOpenPackageWithName(TLI.UnitName+'P',[],false);
  end
else
PackageEditingInterface.DoOpenPackageFile(sDir+TLI.UnitName+'P.lpk',[pofAddT
oRecent],false);

The DoOpenPackageFile with pofRevert is needed to reload the new package and avoid the "disk file changed" warning. But in DoOpenPackageFile Apackage is assigned but not Apackage.Editor, resulting in the editor not being opened. Hence the DoOpenPackageWithName.

Reason for FindPackageWithName not functioning correctly yesterday is because of the package not being re-compiled correctly. I found out I need to do a "Recompile Clean" when a unit of the package has changed. For one reason or another, changing a unit in a package doesn't make it recompile that unit. Is this a bug?

Ludo

Reply by email

Mattias Gaertner
to Ludo Brands: In case I recreate a package that is already installed in lazarus,…
Show quoted text 6 lines
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?

Show quoted text 15 lines
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

Reply by email