Recent

Author Topic: [SOLVED]UGH!!! Lost Form1  (Read 2098 times)

indydev

  • Jr. Member
  • **
  • Posts: 64
[SOLVED]UGH!!! Lost Form1
« on: September 23, 2021, 02:22:48 am »
I have lost Form1 somehow. I have the dreaded project1.lpr(22,35) Error: Identifier not found "Form1" message upon trying to compile.

Project1.lpr has the unit containing Form1 (Main) in its uses clause (See line 13):

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   {$IFDEF HASAMIGA}
  10.   athreads,
  11.   {$ENDIF}
  12.   Interfaces, // this includes the LCL widgetset
  13.   Forms, Main, {<--UNIT CONTAINING "Form1"} ColorTypes
  14.   { you can add units after this };
  15.  
  16. {$R *.res}
  17.  
  18. begin
  19.   RequireDerivedFormResource:=True;
  20.   Application.Scaled:=True;
  21.   Application.Initialize;
  22.   Application.CreateForm(TForm1, Form1); //<--ERROR
  23.   Application.Run;
  24. end.                              
  25.  

and the Main.pas unit has Forms in its uses clause:

Code: Pascal  [Select][+][-]
  1. unit Main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.         Classes, SysUtils, Types, Forms, Controls, Graphics, StdCtrls, Math, XMLRead, DOM, XMLWrite;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.    TForm1 = class(TForm)
  15.         TextArea: TCheckGroup;
  16.         Gutter: TCheckGroup;
  17.     procedure FormCreate(Sender: TObject);
  18.         private
  19.            { private declarations }
  20.         public
  21.            { public declarations }
  22.        end;
  23.  
  24. implementation
  25.  
  26. { TForm1 }
  27.  
  28.  
  29. const
  30.   Foreground = 0;
  31.   Background = 1;
  32.   HexColor = ['A' .. 'F', 'a' .. 'f', '0' .. '9'];
  33.  
  34. var
  35.   Form1: TForm1;
  36.   TxtHolder: String[6];
  37.  
  38.  
  39. {$R *.lfm}
  40.  
  41. { TForm1 }
  42.  
  43.  
  44. procedure TForm1.FormCreate(Sender: TObject);
  45. begin
  46.       TextArea.Checked[Foreground]:= True;
  47.       TextArea.Checked[Background]:= True;
  48.       Gutter.Checked[Foreground]:= True;
  49.       Gutter.Checked[Background]:= True;
  50. end;                                              
  51.  

As far as I can tell, the Main.pas unit has Form1 in all the correct places, and unit "Main" in the right place in the project file, so I am baffled as to what has happened.
« Last Edit: September 23, 2021, 06:53:06 pm by indydev »

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: UGH!!! Lost Form1
« Reply #1 on: September 23, 2021, 02:34:08 am »
This is very difficult to answer. It sounds like an incorrect path.

What happens when you run a simple default Lazarus project?
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

indydev

  • Jr. Member
  • **
  • Posts: 64
Re: UGH!!! Lost Form1
« Reply #2 on: September 23, 2021, 02:38:02 am »
New Application project runs (compiles) just fine.
« Last Edit: September 23, 2021, 02:39:43 am by indydev »

indydev

  • Jr. Member
  • **
  • Posts: 64
Re: UGH!!! Lost Form1
« Reply #3 on: September 23, 2021, 02:44:37 am »
I should have added (sorry), that before this, when I switched unit windows, I noticed a brand new implementation section added to the Main unit and empty procedures. I removed all of them leaving all of the regular procedures and implementation section. It was after this, that it could no longer see the Form1.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: UGH!!! Lost Form1
« Reply #4 on: September 23, 2021, 02:50:53 am »
I should have added (sorry), that before this, when I switched unit windows, I noticed a brand new implementation section added to the Main unit and empty procedures. I removed all of them leaving all of the regular procedures and implementation section. It was after this, that it could no longer see the Form1.

You lost me.

What do you mean "switched unit windows"?

Deleting the new implementation section was probably a mistake.

I can't otherwise understand what you did.
« Last Edit: September 23, 2021, 02:54:14 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

indydev

  • Jr. Member
  • **
  • Posts: 64
Re: UGH!!! Lost Form1
« Reply #5 on: September 23, 2021, 03:06:10 am »
I was looking at another "unit" in Lazarus (tabs along the top of the unit window), when I switched back to the "Main" unit that contains Form1 I noticed that all the procedures were empty, but scrolling down, I could see the completed ones below. I deleted the empty procedures and extra implementation section.  I don't know why or how that happened.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: UGH!!! Lost Form1
« Reply #6 on: September 23, 2021, 03:21:42 am »
No one here has super powers. Your explanation is unclear. Deleting sections created automatically by Lazarus is likely to cause problems.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

indydev

  • Jr. Member
  • **
  • Posts: 64
Re: UGH!!! Lost Form1
« Reply #7 on: September 23, 2021, 03:37:55 am »
OK. thanks for trying.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: UGH!!! Lost Form1
« Reply #8 on: September 23, 2021, 05:12:36 am »
Try again with a simple project not deleting anything produced by Lazarus. Someone here can probably help.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: UGH!!! Lost Form1
« Reply #9 on: September 23, 2021, 06:34:18 am »
Your declaration of Form1 is in the implementation section, it needs to be in the Interface section to be seen by another unit.  So, just move the "var  Form1: TForm1;" bit above the line that says implementation.

Davo

Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. { TForm1 }
  4.  
  5.  
  6. const
  7.   Foreground = 0;
  8.   Background = 1;
  9.   HexColor = ['A' .. 'F', 'a' .. 'f', '0' .. '9'];
  10.  
  11. var
  12.   Form1: TForm1;
  13.   TxtHolder: String[6];
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

indydev

  • Jr. Member
  • **
  • Posts: 64
[SOLVED] Re: UGH!!! Lost Form1
« Reply #10 on: September 23, 2021, 06:52:44 pm »
And so it all makes sense now! When the extra code was mysteriously added I deleted the wrong "implementation." Good grief, it seems so obvious now!

Thank you!

 

TinyPortal © 2005-2018