Jump to content
Sign in to follow this  
limelect

Some components show class =nil

Recommended Posts

---------dockingformpackage.bpl

Empty no component  INSIDE 

 

In my case, some installed packages show empty although they have  components inside

and that is the problem

and this is the stament

  if PackageServices.GetComponentCount(PackageCounter) = 0 then
 

Edited by limelect

Share this post


Link to post
Guest
3 minutes ago, limelect said:

---------dockingformpackage.bpl

Empty no component  INSIDE 

Does it have any component registered to be shown in Tool Palette ? 

No.

 

Are you mixing contained class's and unit files with registered component ?

---

 

Take a break and get some coffee and everything will be cleared by then, trust me on this, it does happen to everyone.

Share this post


Link to post
Guest
7 minutes ago, limelect said:

---------dockingformpackage.bpl

Empty no component  INSIDE 

And that is an answer can be interpreted in two ways

1) it should show that text "Empty no component  INSIDE"

2) it shouldn't and there should something else, if that then what it is ? like you are expecting TExampleDockableForm ?

 

Share this post


Link to post

I guess you did not understand the situation.

1. I install a new component.

2. it is on the list

3. package full with component

4.  Close program Delphi.

5. open Delphi.

6. rerun my program.

7. see component on a pallet

8. package empty

 

Share this post


Link to post

Somehow I'm understanding what's going on:

A 3rd party package is loaded by request (when its component is being used). i.e: zControls package is loaded into the IDE if you drop TzObjectInspector on a form. So when package is not loaded your tst file will not contain components from that package. 

So you have a couple of options

1- make sure that you're using your expert on the right place (when x package is loaded).

2- load x package if its not loaded 
 

for PackageCounter := 0 to PackageServices.PackageCount - 1 do
  begin
    PackageInfo := PackageServices.Package[PackageCounter];
    Unload := False;
    if not PackageInfo.Loaded then
    begin
      // current package is not loaded !
      if PackageInfo.Name = 'zControls_D.bpl' then
      begin
        { Load zControls_D package }
        Unload := True;
        PackageInfo.Loaded := True;
      end;
    end;

    for ComponentCounter := 0 to PackageServices.GetComponentCount(PackageCounter) - 1 do
    begin
      xx := TPersistentClass(GetClass2(PackageCounter, ComponentCounter));
      if not(xx = nil) then
      begin
        s.Add(xx.ClassName);
      end
      else
        s.Add('nil- ' + InstalledComponentName);
    end;

    if Unload then
    begin
      { No longer need package ? => Unload it }
      PackageInfo.Loaded := False;
    end;
  end;
  s.SaveToFile('C:\Users\smp\Desktop\tst.txt'); // Now this will contain TzObjectInspector !

 

Share this post


Link to post

@Mahdi Safsafi you are wrong. Unless I did not understand you.

We are talking about components being on the component/Pallet. Once

you register it I should see it inside the package. simple.

I have made along time ago BPL analyzer and more. It scans all the bpl in the Delphi directory

and analyzes them. see the pictures.

Your component is in the bpl.(the package). The program

should be able to read the package simple.

In my case, it does not. Something happens that Delphi did not foresee. Maybe I am wrong.

So now I am looking for a DIFFERENT way to read the packages.

Screenshot - 03_11_2020 , 13_41_54.jpg

Screenshot - 03_11_2020 , 13_45_29.jpg

Share this post


Link to post

@Mahdi Safsafi i would like to elaborate a little.

It all started with this 

 

So dave helped a lot and i have what i needed

But during the use of the tool i had what you fixed.

But then i found that some components i do not show and

this is where the last problem stand

Edited by limelect

Share this post


Link to post
1 hour ago, limelect said:

@Mahdi Safsafi you are wrong. Unless I did not understand you.

Maybe you didn't understand my comment...

Quote

So now I am looking for a DIFFERENT way to read the packages.

A component class is just a reference that resides inside a package (which is just a dll). IDE needs to load a given package(dll) inside its address space in order to get component class and accessing it. 

Quote

We are talking about components being on the component/Pallet.

Quote

If a component is on the pallet it is loaded, right?

 

Its not about being on the pallet or not ! standard packages (core packages) are loaded by defaults when the IDE starts up hence you can get their class ... 3rd party packages are loaded when you use them(i.e: dropping a component on a form) hence you can get their class only if they were loaded. 


PS:I think that you didn't test the code I gave ... So I suggest that you try it.

 

Share this post


Link to post

@Mahdi Safsafi on second found not loaded it breaks

I have to load All of them for viewing.

So with your advice, this is the test bench

and it fails at the second iteration

      if not PackageInf.Loaded then
      begin
        s.Add('--------- not loaded   ' +
          PackageServices.PackageNames[PackageCounter]);
        PackageInf.Loaded := True;<<<<here
        Unload := True;
      end;

 

is my var correct ?  PackageInf: IOTAPackageInfo;

Stack overflow  may be some how free?

 

DockingForm (3).zip

Edited by limelect

Share this post


Link to post

Of course it will fail... you're loading all packages ! Some packages are just incompatible.

Basically you need to

1- Skip IDE package and runtime package -> See IOTAPackageInfo.[IDEPackage, RuntimeOnly, DesigntimeOnly].

2- Skip incompatible packages -> See IOTAPackageInfo.[Producer, Consumer] 

3- Skip all packages that do not appear on the Palette -> See register Computer\HKEY_CURRENT_USER\Software\Embarcadero\BDS\20.0\Palette

For 1 and 2 don'f forget to read the documentation. 

 

PS: I saw how you manually inlined GetClass2 ... That's definitely not the way how to go for.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×