Recent

Author Topic: Solved: User Components  (Read 4704 times)

PatBayford

  • Full Member
  • ***
  • Posts: 125
Solved: User Components
« on: July 19, 2017, 05:15:07 am »
Some help please for a relatively new Lazarus user, (migrant from Delphi). Exactly at what point does a "dropped" component get assigned it's name?
I ask because, unlike in Delphi, most user written components do not seem to get "named" in Lazarus.
The caption IS usable, but it appears that the Name property is not assigned.
« Last Edit: July 26, 2017, 12:21:31 am by PatBayford »
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

balazsszekely

  • Guest
Re: User Components
« Reply #1 on: July 19, 2017, 07:18:10 am »
Hi PatBayford,

Please open project "lazarus.lpi" from $(LazarusDir)\IDE directory, then open "customformeditor.pp" file(see attached screenshot1). As you can see your component name is assigned, more over after assignment is checked for duplicate. Since every component must have a valid name(see attached screenshot2), any user written component should have a name. Perhaps there is an internal exception in your code that causes the issue.

PS: You can set a breakpoint to "customformeditor.pp"(line 2260)  and check what is happening with your component.

regards,
GetMem
« Last Edit: July 19, 2017, 07:28:58 am by GetMem »

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: User Components
« Reply #2 on: July 19, 2017, 10:48:00 pm »
Hi PatBayford,

Please open project "lazarus.lpi" from $(LazarusDir)\IDE directory, then open "customformeditor.pp" file(see attached screenshot1). As you can see your component name is assigned, more over after assignment is checked for duplicate. Since every component must have a valid name(see attached screenshot2), any user written component should have a name. Perhaps there is an internal exception in your code that causes the issue.

PS: You can set a breakpoint to "customformeditor.pp"(line 2260)  and check what is happening with your component.

regards,
GetMem
Thanks - tried that, looks like my component never calls the CustomFormEditor! I will tidy up the code and post a zip of the project later. In the meantime, attached is a screenshot - note the empty (green) Label, and the message box contents.
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: User Components
« Reply #3 on: July 19, 2017, 11:52:18 pm »
Attached is a zip file holding the project files.
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

balazsszekely

  • Guest
Re: User Components
« Reply #4 on: July 20, 2017, 07:17:15 am »
@PatBayford
I cannot run your project or install the package. Contains unresolved dependencies, missing packages like "mycontrols", "gamebits". Where is TListViewComponentEditor class declared? Cannot find it. Please attach a package that can be installed.
« Last Edit: July 20, 2017, 07:40:28 am by GetMem »

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: User Components
« Reply #5 on: July 21, 2017, 12:11:36 am »
Sorry about the unresolved dependencies - lack of familiarity with Lazarus! Delphi holds your hand too well!
I have attached a new zip which seems to resolve any problems - I have test installed the package.
The Component and Property editors are strictly place holders, pending resolution of problems obtaining correct references to the active component. The framework supplied does not prevent the package installing.
You will note that the LabeledListView has a name, but the embedded label is empty, suggesting it does not, as the default behaviour of a Label is to set it's Caption property to it's Name.
« Last Edit: July 21, 2017, 06:16:20 am by PatBayford »
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: User Components
« Reply #6 on: July 24, 2017, 12:24:03 am »
More apologies - forgot to attach the zip first time round - it is there now, and repeated here
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: User Components
« Reply #7 on: July 24, 2017, 12:35:27 pm »
The Lazarus Designer does ensure that a dropped component is named uniquely.
So the first TLabeledListView dropped on a form is named LabeledListView1.
However, the component editor that does this has no idea that the new component has subcomponents.
If you want subcomponents named, you have to do this yourself in a custom method called in the main component's constructor.
You can get ideas for this from the ClassNameToComponentName function in Propedits.pp

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: User Components
« Reply #8 on: July 25, 2017, 01:51:05 am »
Thank you Howard, that gives me a place to start. Trying to make sure that my components comply with the "normal" behaviour for consistency.
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: User Components
« Reply #9 on: July 26, 2017, 12:21:08 am »
Solved simply by assigning value to Name within custom Create - thanks Howard
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Solved: User Components
« Reply #10 on: July 26, 2017, 12:28:08 am »
Just a side-note: Run-time created components usually do not need a name at all since they can be accessed by means of their variable name. Having the name empty avoids any duplicate name issues. The property Name is essential for the object inspector to identify components at designtime.
« Last Edit: July 26, 2017, 01:16:29 am by wp »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Solved: User Components
« Reply #11 on: July 26, 2017, 12:50:27 am »
Why do you give a run-time created component a name at all? In most cases a name is not needed since you have the variable name to access a component. Having the name empty avoids any duplicate name issues. The property Name is essential for the object inspector to identify components at designtime.
and for the streaming mechanism to load components during form, datamodule or frame creation.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018