Recent

Author Topic: control reference is lost  (Read 3046 times)

waltfair

  • New Member
  • *
  • Posts: 21
  • Walt Fair, PHD, PE. Engineer and software junkie
control reference is lost
« on: April 28, 2023, 10:06:49 pm »
I have a main form with several controls on it.
In the code, I set and retrieve values from the controls. Nothing fancy and it worked as expected.
After some time I saved all the files and tried to rebuild with Run | Build from the GUI, no code changes had been madesince the last successful build and test run.
Now

I get a failed build with the message: identifier not found referencing one of the controls.
The control is obviously there in the form designer and is also listed in the Form declaration.

Any idea how to get this sorted out?
What could I have done wrong?
This is on Windows 10, but I had the same problem on Linux.
« Last Edit: April 28, 2023, 10:11:30 pm by waltfair »

Josh

  • Hero Member
  • *****
  • Posts: 1350
Re: control reference is lost
« Reply #1 on: April 28, 2023, 10:10:47 pm »
what name did you give the control?
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

waltfair

  • New Member
  • *
  • Posts: 21
  • Walt Fair, PHD, PE. Engineer and software junkie
Re: control reference is lost
« Reply #2 on: April 29, 2023, 04:39:53 pm »
So, I started over with a fresh project and I can't get the reference to my TStringGrid added in the designer

Here's the designer-generated declaration in the TForm, note the grd1 declaration is clearly there.

TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    mnuexit: TMenuItem;
    mnusave: TMenuItem;
    mnuopen: TMenuItem;
    mnuFile: TMenuItem;
    grd1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure mnuexitClick(Sender: TObject);
    procedure mnuFileClick(Sender: TObject);
    procedure mnusaveClick(Sender: TObject);
when I try to build I get an identifier not found grd1 error in this line of code:

    if(grd1.Cells[1,r] <> '') then

Is this a problen in the designer or what did I do wrong?
« Last Edit: April 29, 2023, 04:57:15 pm by waltfair »

cdbc

  • Hero Member
  • *****
  • Posts: 1786
    • http://www.cdbc.dk
Re: control reference is lost
« Reply #3 on: April 29, 2023, 04:59:58 pm »
Hi
Please show us all the code in the unit that borks... We can't see anything from the interface part alone. uses clause(s) and implementation part for starters.
And please put your code in code tags (you click on the # button) and put your code in between the tags. Then your code looks like this:
Code: Pascal  [Select][+][-]
  1. TForm1 = class(TForm)
  2.     MainMenu1: TMainMenu;
  3.     MenuItem1: TMenuItem;
  4.     mnuexit: TMenuItem;
  5.     mnusave: TMenuItem;
  6.     mnuopen: TMenuItem;
  7.     mnuFile: TMenuItem;
  8.     grd1: TStringGrid;
  9.     procedure FormCreate(Sender: TObject);
  10.     procedure mnuexitClick(Sender: TObject);
  11.     procedure mnuFileClick(Sender: TObject);
  12.     procedure mnusaveClick(Sender: TObject);
  13. ...
  14.   if(grd1.Cells[1,r] <> '') then ...
  15. // i assume the above line is situated in an event-handler of the form?!?
  16. // otherwise it'd be more like:  
  17.   if(Form1.grd1.Cells[1,r] <> '') then ...
  18.  
Btw. I think it's a simple typo, had one myself recently  %)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

waltfair

  • New Member
  • *
  • Posts: 21
  • Walt Fair, PHD, PE. Engineer and software junkie
Re: control reference is lost
« Reply #4 on: April 30, 2023, 03:27:37 am »
Benny, thanks for the reply, but A simple typo doesn't explain why it worked at first and then quit working with error that the identifier is unknown.

All of the code is designer generated, except for the one line that gives the error now, even though it worked before

cdbc

  • Hero Member
  • *****
  • Posts: 1786
    • http://www.cdbc.dk
Re: control reference is lost
« Reply #5 on: April 30, 2023, 04:03:56 am »
Hi
Show us the code... We're stuck without it. I don't think it's the designer, because, up until now, only three people have mentioned having a bug like yours, handoko, yourself and I  :) There would have been a lot more commotion going on, if it were a bug in the designer.  ;)
We can help you look for the culprit...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

cdbc

  • Hero Member
  • *****
  • Posts: 1786
    • http://www.cdbc.dk
Re: control reference is lost
« Reply #6 on: April 30, 2023, 06:29:45 am »
Hi
Just ran into something like this...
Are you by any chance using this construct:
Code: Pascal  [Select][+][-]
  1. ...
  2.   with someclass do begin
  3.     ...
  4.   end;
  5.  
If so, then it's enough to add a parameter to a method, to screw things up, see attachment...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

dseligo

  • Hero Member
  • *****
  • Posts: 1452
Re: control reference is lost
« Reply #7 on: April 30, 2023, 09:28:33 am »
So, I started over with a fresh project and I can't get the reference to my TStringGrid added in the designer

Upload whole project here (menu Project/Publish project in Lazarus).

Quote
Is this a problen in the designer or what did I do wrong?

Probably you did something.
Maybe you renamed control name in unit source, but not in form.

waltfair

  • New Member
  • *
  • Posts: 21
  • Walt Fair, PHD, PE. Engineer and software junkie
Re: control reference is lost
« Reply #8 on: May 01, 2023, 03:45:42 pm »
P
Quote
robably you did something.
Maybe you renamed control name in unit source, but not in form.
No, I never mess with the designer generated source code. I always just add code to the event methods.
« Last Edit: May 02, 2023, 06:45:51 pm by waltfair »

cdbc

  • Hero Member
  • *****
  • Posts: 1786
    • http://www.cdbc.dk
Re: control reference is lost
« Reply #9 on: May 01, 2023, 04:14:15 pm »
Hi
It's a scope-thingy... You are acting on variables belonging to TForm1 from outside the class.
Code: Pascal  [Select][+][-]
  1.   if(grd1.Cells[1,r] <> '') then ...  // <--- ?!?
  2. // i assume the above line is situated in
  3. // an event-handler of the form?!?
  4. // otherwise it'd be more like:  
  5.   if(Form1.grd1.Cells[1,r] <> '') then ...  // <--- Form1.
  6. //     ^ but only if you have instantiated
  7. //        the form first, else AV!
  8.  
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

waltfair

  • New Member
  • *
  • Posts: 21
  • Walt Fair, PHD, PE. Engineer and software junkie
Re: control reference is lost
« Reply #10 on: May 02, 2023, 06:45:03 pm »
Quote
Hi
It's a scope thingy... You are acting on variables belonging to TForm1 from outside the class.
Code: Pascal  [Select]
No, it is clearly within the TFORM1 implementation section.
It just seems weird!

TRon

  • Hero Member
  • *****
  • Posts: 3810
Re: control reference is lost
« Reply #11 on: May 02, 2023, 07:00:29 pm »
No, it is clearly within the TFORM1 implementation section.
That statement does not necessarily mean that it is in the scope of the class TForm1. There is a difference.

No code, no cure  :)
I do not have to remember anything anymore thanks to total-recall.

Bart

  • Hero Member
  • *****
  • Posts: 5497
    • Bart en Mariska's Webstek
Re: control reference is lost
« Reply #12 on: May 02, 2023, 07:01:03 pm »
Again: attach the source here.
Now we're just using crystal balls.

Bart

waltfair

  • New Member
  • *
  • Posts: 21
  • Walt Fair, PHD, PE. Engineer and software junkie
Re: control reference is lost
« Reply #13 on: May 02, 2023, 10:20:29 pm »
I won't bother posting all the code. Since things are working now,

I appreciate the comments, but I've moved on to other things.
Thanks again,

Walt Fair, PHD, PE

 

TinyPortal © 2005-2018