Recent

Author Topic: How to open a form when a component class is missing?  (Read 1206 times)

Cascade

  • New Member
  • *
  • Posts: 22
How to open a form when a component class is missing?
« on: October 17, 2024, 12:21:36 pm »
I'm having trouble opening a converted form in the IDE, because it contains a missing component.  How can I open the form to fix it?

I've attached the error message.  Clicking the Cancel button seems to abort loading of the form, rather than just the cancelling the offending component.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1291
Re: How to open a form when a component class is missing?
« Reply #1 on: October 17, 2024, 12:49:34 pm »
Open .lfm file for form. Remove the part for missing  componet.
✨ 🙋🏻‍♀️ 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. 💁🏻‍♀️

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to open a form when a component class is missing?
« Reply #2 on: October 17, 2024, 01:36:35 pm »
Thanks Joanna,

I've given that a try (opened the .lfm file in an external editor - BBEdit) and carefully removed the offending object.  I then removed its matching declaration from the associated .pas file.

When I try to open that unit now, the IDE opens it as two separate tabs - one for .pas and another alongside it for .lfm displayed as code (selected).  I'm then unable to click away from the .lfm tab - it keeps jumping back to that tab.  I've checked the .lfm file again to make sure I only deleted one object from it, and it looks OK.  I must have got something wrong.  Seems strange.

dseligo

  • Hero Member
  • *****
  • Posts: 1452
Re: How to open a form when a component class is missing?
« Reply #3 on: October 17, 2024, 01:45:31 pm »
I've given that a try (opened the .lfm file in an external editor - BBEdit) and carefully removed the offending object.  I then removed its matching declaration from the associated .pas file.

Did you close Lazarus before editing in external editor? If not, try to close Lazarus first.

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to open a form when a component class is missing?
« Reply #4 on: October 17, 2024, 02:08:17 pm »
Hi dseligo - Yes, I closed Lazarus.  Had to delete the project .lps file before the IDE would function again.  But you got me thinking, and I think I may have fixed it by changing the .lfm line endings to CRLF (suspect my external text editor changed to LF only?).  Then instead of deleting the offending object, I changed its class to a TPanel instead, as a kind of placeholder.

I'm not certain it's OK yet - but the form has opened OK in the IDE.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1291
Re: How to open a form when a component class is missing?
« Reply #5 on: October 17, 2024, 02:15:49 pm »
Thanks Joanna,

I've given that a try (opened the .lfm file in an external editor - BBEdit) and carefully removed the offending object.  I then removed its matching declaration from the associated .pas file.

When I try to open that unit now, the IDE opens it as two separate tabs - one for .pas and another alongside it for .lfm displayed as code (selected).  I'm then unable to click away from the .lfm tab - it keeps jumping back to that tab.  I've checked the .lfm file again to make sure I only deleted one object from it, and it looks OK.  I must have got something wrong.  Seems strange.
I always fix the lfm files using Lazarus ide. So I’ve never had that problem. Have you tried restarting the Lazarus ide? Sometimes it gets confused if files changed on disk no longer match files open in editor
✨ 🙋🏻‍♀️ 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. 💁🏻‍♀️

LV

  • Full Member
  • ***
  • Posts: 197
Re: How to open a form when a component class is missing?
« Reply #6 on: October 17, 2024, 06:15:31 pm »
Lazarus IDE is an intelligent tool that performs many tasks automatically. Some of these functions may be visible in the Source Editor, while others occur behind the scenes when Lazarus creates and modifies the .lfm files. Although it is possible to manually edit these files in an attempt to outsmart Lazarus, this approach can be risky. For instance, you can create forms and components manually and then manage them using the Object Inspector in the Lazarus IDE.
https://forum.lazarus.freepascal.org/index.php/topic,68925.0.html

LV

  • Full Member
  • ***
  • Posts: 197
Re: How to open a form when a component class is missing?
« Reply #7 on: October 17, 2024, 06:58:30 pm »
I tried to replicate the error you experienced and have attached a screenshot for your reference.

It seems that the component was either intentionally or accidentally deleted in the Source Editor. To resolve this issue, I do the following steps:

1. Remove the component from the LFM file.
2. Go to the menu and select "Run," then choose "Build."
3. Finally, select "Run" from the "Run" menu.

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to open a form when a component class is missing?
« Reply #8 on: October 18, 2024, 10:55:35 am »
Hi LV - Thank you, yes that's roughly the error I was seeing (though I didn't get the option to Ignore, only Cancel).

Thank you everyone for your assistance - I have successfully opened the form now.

What do people think to the idea of having the IDE swap out any missing components for a simple TPlaceholder component when a problematic form is opened?  TPlaceholder would essentially be a TPanel object in all but name.  It could have a Caption indicating the missing class name.

A placeholder would maintain the layout, and enable a user to edit and correct the form visually in the form designer, without having to risk manually editing the text of the lfm file.  It could make the IDE more robust.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1291
Re: How to open a form when a component class is missing?
« Reply #9 on: October 18, 2024, 01:33:26 pm »
Better to create everything at runtime if you can.
I’m curious about your form.pas file if you’re willing to share it.
✨ 🙋🏻‍♀️ 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. 💁🏻‍♀️

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to open a form when a component class is missing?
« Reply #10 on: October 19, 2024, 04:31:24 pm »
I think I can share it - if I can figure out how to send you a message.  I've uploaded a 5 min video where I eventually get the form to load:

https://www.youtube.com/watch?v=rOXgkFukXhA
(I suggest selecting a faster playback speed)

 :)

 

TinyPortal © 2005-2018