Recent

Author Topic: [SOLVED in another way] Unable to find the component class  (Read 4440 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
[SOLVED in another way] Unable to find the component class
« on: July 26, 2017, 03:38:47 am »
Something strange is happening...
I'm making a more complex TForm behaviour, therefore I just create a child of TForm and it works fine.
BUT if I create a child of a child of TForm I get an error on loading the project:
Quote
Unable to find the component class "TSomeForm".
It is not registered via RegisterClass and no lfm was found.
It is needed by unit: ...

I.e. this code loads fine:
Code: Pascal  [Select][+][-]
  1. type TForm_1 = class(TForm)
  2.   public
  3.     myvar1: integer;
  4. end;
  5. type
  6.   TForm1 = class(TForm_1)
  7.   private
  8.   public
  9.   end;
and this one gives an error on each project open (actually on first showing of form's window):
Code: Pascal  [Select][+][-]
  1. type TForm_1 = class(TForm)
  2.   public
  3.     myvar1: integer;
  4. end;
  5. type TForm_2 = class(TForm_1)
  6.   public
  7.     myvar2: integer;
  8. end;
  9. type
  10.   TForm1 = class(TForm_2)
  11.   private
  12.   public
  13.   end;
TForm1 was automatically created in a "normal" way (File>New>Application). Maybe I've messed up something with resource file by doing this way?

Minimal example attached.

P.S. Everything works perfectly if I ignore the error. It would just reappear at each form window first opening.
Lazarus 1.8.0RC3, FPC3.0.3, Debian Linux
« Last Edit: October 29, 2017, 11:23:08 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: Unable to find the component class
« Reply #1 on: October 29, 2017, 08:53:01 am »
Still an issue in Lazarus 1.9.0 2017-10-20 FPC 3.1.1
Any help here would be very appreciated  :-[ as it becomes a bit annoying with increasing number of forms...
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Unable to find the component class
« Reply #2 on: October 29, 2017, 09:18:56 am »
are you talking about run time or design time? if run time then simple add an initialization section in your unit and add a call to registerclass for the form in question on the design time on the other hand you need to change your thinking a bit first you need to make sure that Tform_2 is a visual form aka its a "normal" form and tform1 inherits from it normally that will ensure that the IDE knows where to find what.
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

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: Unable to find the component class
« Reply #3 on: October 29, 2017, 09:36:39 am »
are you talking about run time or design time?
The issue is design-time.
Run-time everything is flawless. Even design-time everything is working smoothly except a nasty pop-up every first "open".
Quote
you need to make sure that Tform_2 is a visual form aka its a "normal" form
Emmm... and how do I do that? Inheriting TForm_1 which inherits TForm seems not enough.
I couldn't find anywhere pure TForm is registered in the files (except, maybe, in a binary *.res).

The more "Extended explanation" (real-life):
I have an editor which edits game data.
Game data is represented by a set o XML-files (databases) and every is different.
Some game data require the editor form to be multilingual (e.g. containing game texts) and some don't (e.g. images, numeric values).
Therefore the structure is:
TWriterForm = class(TForm)
with abstract "write/read" procedure. Main form enumerates all its spawned forms and launches "write" on every of those if "write all" button is pressed. Also it handles some other generic data such as isChanged, isVisible logging etc.
However, language-dependent forms are different and therefore they
TLanguageForm = class(TWriterForm)
with current_language variable, language switch, and synchronize abilities. Also it needs all the functionality of TWriterForm.
« Last Edit: October 29, 2017, 09:47:16 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Unable to find the component class
« Reply #4 on: October 29, 2017, 10:16:50 am »
are you talking about run time or design time?
The issue is design-time.
Run-time everything is flawless. Even design-time everything is working smoothly except a nasty pop-up every first "open".
Quote
you need to make sure that Tform_2 is a visual form aka its a "normal" form
Emmm... and how do I do that? Inheriting TForm_1 which inherits TForm seems not enough.
Create a new application (project\new project->application). It has a single form which will become your base form. Select file\New ... on the tree on the left of the screen select inherited project component under inherited items and on the list on the right select form1. Make sure that unit1 is in the interface uses clause of unit2 and rename the form from tform11 to tform2 repeat until you have your hierarchy. open the lfm files in the editor(right click on the form and select view source (.lfm)) Make sure that it starts with inherited TFormX instead of object TformX (except the form1). That should solve the error.
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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Unable to find the component class
« Reply #5 on: October 29, 2017, 10:38:56 am »
The more "Extended explanation" (real-life):
I have an editor which edits game data.
Game data is represented by a set o XML-files (databases) and every is different.
Some game data require the editor form to be multilingual (e.g. containing game texts) and some don't (e.g. images, numeric values).
Therefore the structure is:
TWriterForm = class(TForm)
with abstract "write/read" procedure. Main form enumerates all its spawned forms and launches "write" on every of those if "write all" button is pressed. Also it handles some other generic data such as isChanged, isVisible logging etc.

this is a problem of wrong position. 1) the write capability must never be part of the form the forms rensposibility starts the moment you hand it the xml structure to show and ends the moment it passes the data from the editors to the xml structure. it should not care if this is going to be writen or send by email the same way an open dialog does not create the file for you it returns the selected filename only. TLanguageForm = class(TWriterForm)


However, language-dependent forms are different and therefore they
with current_language variable, language switch, and synchronize abilities. Also it needs all the functionality of TWriterForm.
Why are language depended forms different? Does Current_language change while the form is loaded? Synchronize with what? Why is a form responsible for synchronization? To put it simple a form is only a view of the data in a specific format. It should only react on changes not trigger them.
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

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: Unable to find the component class
« Reply #6 on: October 29, 2017, 11:18:31 am »
Quote
the write capability must never be part of the form
Hmmm... sounds like a very nice step. If I separate the data and the interface, that should prove much more convenient to process (especially now, as the data would become "modular" - and I had very poor understanding on how to handle "modules").
In that case the issue will be solved in a much more elegant way. Thanks a lot!
« Last Edit: October 29, 2017, 11:23:44 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

 

TinyPortal © 2005-2018