Recent

Author Topic: Auto insert unit to uses line when component drop to the form  (Read 4278 times)

totya

  • Hero Member
  • *****
  • Posts: 720
Hi!

I have a simple component (package) with few unit. When the component dropped to the form, the main component unit (and strictly used units)  inserted to the project uses line. It's okay. But I want (auto) inserted more unit (common tpyes unit example). How can I do this? Thanks! :)

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Auto insert unit to uses line when component drop to the form
« Reply #1 on: June 19, 2018, 07:49:45 am »
I have a simple component (package) with few unit. When the component dropped to the form, the main component unit (and strictly used units)  inserted to the project uses line. It's okay. But I want (auto) inserted more unit (common tpyes unit example). How can I do this? Thanks! :)
Sorry, I can't understand what you mean.
Can you attach a sample package with your difficulties?
« Last Edit: June 19, 2018, 09:32:08 am by valdir.marcos »

balazsszekely

  • Guest
Re: Auto insert unit to uses line when component drop to the form
« Reply #2 on: June 19, 2018, 08:59:03 am »
@valdir.marcos
Quote
Sorry, I can't understand what you mean?
I think he explained pretty clear what he is trying to achieve. Let's say you have a package with he following units: "mainunit", "someotherunit", "commonunit". When he drops the component to a form1(unit1), Lazarus automatically insert "mainunit" to the uses list. He would like some mechanism by which "someotherunit" and "commonunit" would be also automatically inserted. I don't think such a mechanism exists but I might be wrong.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Auto insert unit to uses line when component drop to the form
« Reply #3 on: June 19, 2018, 09:31:52 am »
@valdir.marcos
Quote
Sorry, I can't understand what you mean.
I think he explained pretty clear what he is trying to achieve. Let's say you have a package with he following units: "mainunit", "someotherunit", "commonunit". When he drops the component to a form1(unit1), Lazarus automatically insert "mainunit" to the uses list. He would like some mechanism by which "someotherunit" and "commonunit" would be also automatically inserted. I don't think such a mechanism exists but I might be wrong.
Now it's clear.  :)

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Auto insert unit to uses line when component drop to the form
« Reply #4 on: June 19, 2018, 04:47:28 pm »
@GetMem Yes, indeed / Igen, valóban.

But I think this isn't a big question. Meanwhile I found approximate solution, if I use inc files for implementations, I can inserted these via {$I}. directive, so I got one big unit virtually.


Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1311
    • Lebeau Software
Re: Auto insert unit to uses line when component drop to the form
« Reply #5 on: June 19, 2018, 08:45:53 pm »
I have a simple component (package) with few unit. When the component dropped to the form, the main component unit (and strictly used units)  inserted to the project uses line. It's okay. But I want (auto) inserted more unit (common tpyes unit example). How can I do this?

I'm not sure if there is a way to do this in FreePascal/Lazarus.

In Delphi, you can implement and register a custom TSelectionEditor-derived class and have it override the virtual `RequiresUnits()` method.  Any unit name that is passed to the method's Proc() callback parameter gets added to the `uses` clause.

If there is a FreePascal/Lazarus equivalent, I would like to know as well (as Indy uses this feature in Delphi).
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Auto insert unit to uses line when component drop to the form
« Reply #6 on: June 19, 2018, 09:03:43 pm »
"One big unit".... Not a good idea ....

But there is another way that may help.

I assume, that the extra units, that are not currently added are only needed for code you will add? E.g, so you can have local variables with types defined in the extra unit?

In that case install the package "cody".
Assign the "Unit/Identifier Dictionary" to a keyboard shortcut.

Now if you start typing the name of a constant or type, you can invoke the dictionary and it will offer you matching types, and if you confirm add the unit that they are declared in.

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: Auto insert unit to uses line when component drop to the form
« Reply #7 on: June 19, 2018, 09:13:04 pm »
In that case install the package "cody".
Assign the "Unit/Identifier Dictionary" to a keyboard shortcut.

Now if you start typing the name of a constant or type, you can invoke the dictionary and it will offer you matching types, and if you confirm add the unit that they are declared in.

Good. I was looking for that functionality. On Trunk built with fpcupdeluxe seems that is installed by default.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Auto insert unit to uses line when component drop to the form
« Reply #8 on: June 19, 2018, 09:36:10 pm »
"One big unit".... Not a good idea ....

Hi, thanks for the answer!

..."virtually" as I wrote. I saw it solution in Lazarus Source ;) So, it isn't a good idea? ;)

stdctrls.pp:

Code: Pascal  [Select][+][-]
  1. {$I customgroupbox.inc}
  2. {$I customcombobox.inc}
  3. {$I customlistbox.inc}
  4. {$I custommemo.inc}
  5. {$I customedit.inc}
  6. {$I customlabel.inc}
  7. {$I customcheckbox.inc}
  8.  
  9. {$I scrollbar.inc}
  10. {$I memoscrollbar.inc}
  11. {$I memostrings.inc}
  12.  
  13. {$I buttoncontrol.inc}
  14. {$I buttons.inc}
  15.  
  16. {$I checkbox.inc}
  17. {$I radiobutton.inc}
  18. {$I togglebox.inc}
  19.  
  20. {$I customstatictext.inc}
  21.  

This technique help eliminate other problems too.. because in one unit, I have more control for class variables, for example the "private" works differently, for example. private isn't private, I can use it, or I need strict private to real private.

Quote
I assume, that the extra units, that are not currently added are only needed for code you will add? E.g, so you can have local variables with types defined in the extra unit?

I definded own important type, for example similar of this:

Code: Pascal  [Select][+][-]
  1. TSelectMode = (smOne, smTwo);    

This is not added automatically, if this isn't defined (or used) in the main (registered) unit.

Quote
In that case install the package "cody".
Assign the "Unit/Identifier Dictionary" to a keyboard shortcut.

Now if you start typing the name of a constant or type, you can invoke the dictionary and it will offer you matching types, and if you confirm add the unit that they are declared in.

Thanks for the idea, but as I read is help for me, but I want help for users, who uses my package... ;)

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: Auto insert unit to uses line when component drop to the form
« Reply #9 on: June 19, 2018, 09:57:44 pm »
Thanks for the idea, but as I read is help for me, but I want help for users, who uses my package... ;)

Well, I think that will help any Lazarus user, using your package as well. Just add that to the documentation of your package, that is recommended to use Cody.

 

TinyPortal © 2005-2018