Recent

Author Topic: custom component without empty properties (name and parent)  (Read 1659 times)

Ernest

  • Newbie
  • Posts: 6
custom component without empty properties (name and parent)
« on: January 05, 2024, 04:33:25 pm »
Hallo everone,

Intro
I am struggling to create a custom component with two-depth classes (base class is extended and put into a panel). The aim is to create a panel with desired amount of double labels (double label = paramter + value).
The problem i encountered is, that the "Name" parameter is not set automatically (it should be though... see pics below) and it causes problems while saving (component causing a freezing of the whole IDE making it unuseful in a big project).

Question
How can i solve it? What am i doing wrong? What is the convention / routine to make my own complex custom component?

Source for you
My reduced *.lpk package and example project are attached below.
The zip contains the package which installs the described component in the additional tab 'ForumQuestions' in component pallete.

Additional
The sources like delphi-treff (https://www.delphi-treff.de/tutorials/vcl/komponenten-entwicklen/5/) or wiki (https://wiki.freepascal.org/How_To_Write_Lazarus_Component) aren't helpful in that matter.

Thanks in advance!
Ernest

Lazarus 2.2.6 (rev lazarus_2_2_6) FPC 3.2.2 x86_64-win64-win32/win64
Tags: Subcomponent, embeded compoent, nested component, component in component,
« Last Edit: January 05, 2024, 04:35:38 pm by Ernest »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: custom component without empty properties (name and parent)
« Reply #1 on: January 06, 2024, 07:52:30 am »
The problem i encountered is, that the "Name" parameter is not set automatically (it should be though... see pics below)
I don't think "Name" property is set automatically into any subcomponent anywhere.
You can make your own code to find unique names for them or use CreateUniqueComponentName from unit FormEditingIntf or unit ComponentEditors, both in IdeIntf package. Search how other components call it.
The actual function implementation is TCustomFormEditor.CreateUniqueComponentName.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Ernest

  • Newbie
  • Posts: 6
Re: custom component without empty properties (name and parent)
« Reply #2 on: January 09, 2024, 03:13:40 pm »
Hi @JuhaManninen,

Thanks for your answer but i need to check if it will help me.

The empty name property is for me an indicator that something is wrong.
The labels (=subcomponents) as published property have their parent and this is the component, which get its name when it is dropped on the form (so its name is written next to the property in Obejct Inspector, OI). This happens automatically through the TForm although i don't know how exactly. The instance of TForm is the parent and the owner of the component.

My question refers to the subcomponent of the labels (=subcomponent). The label is the parent of its internal objects which is represented as published properties Opt1LabelLeft and Opt2LabelRight. The problem is, there is no possibility to choose any object name so it is parentless and it means it is wrong implemented. As example, if you use TDataSource you need to assign the DataSet property. But as long as no data set is existing there can be no entry.

In my component, i could just add these labels on the panel on the TForm but i want to capsulate the objects to have my complex structure in Object Inspector as short as it is possible.

Any other ideas how can i fix it?
Do you know any other components which are so complex and comparable with mine?

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1271
Re: custom component without empty properties (name and parent)
« Reply #3 on: January 12, 2024, 11:42:28 pm »
Things created at runtime can have their name declared in the constructor.
Parent must be explicitly assigned too otherwise it will be nil . Using ide to create things at design time does a lot for you automatically.
« Last Edit: January 12, 2024, 11:46:09 pm by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Josh

  • Hero Member
  • *****
  • Posts: 1346
Re: custom component without empty properties (name and parent)
« Reply #4 on: January 13, 2024, 12:16:13 am »
Have you checked out

https://wiki.freepascal.org/How_To_Write_Lazarus_Component

Towards the bottom heading

Using embedded (visual) components


Search for Compound Components may give some example
under misc tab checkout TButtonPanel, may give you some ideas
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: custom component without empty properties (name and parent)
« Reply #5 on: January 13, 2024, 02:19:24 am »
I still do not understand the purpose that an internal used class should be exposed to the outside at all.
When I do such, I just offer properties that a user could touch, in no way I would want that a user has full control over my internals and let them in worst case break.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: custom component without empty properties (name and parent)
« Reply #6 on: January 13, 2024, 07:41:47 am »
Sorry I missed your reply earlier.

The empty name property is for me an indicator that something is wrong.
So you must give it a name.  :)

Quote
The labels (=subcomponents) as published property have their parent and this is the component, which get its name when it is dropped on the form (so its name is written next to the property in Obejct Inspector, OI). This happens automatically through the TForm although i don't know how exactly.
The form designer has code for it.

Quote
Any other ideas how can i fix it?
I think my original idea is still valid: Fill the name properties yourself when the component is created.
Using CreateUniqueComponentName prevents any potential name clash with other components, although I am not sure if it even matters with those subcomponents.

Quote
Do you know any other components which are so complex and comparable with mine?
There are components with subcomponents. TLabeledEdit comes to mind. It has property EditLabel with name "SubLabel".
TButtonPanel is another as Josh suggested. Its buttons have names.
Please also study 3rd party components found in OPM.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018