Recent

Author Topic: copy and paste:Identifier not found "Button13  (Read 697 times)

pentilisea

  • Guest
copy and paste:Identifier not found "Button13
« on: March 07, 2023, 11:12:26 am »
Hi,
want to copy and paste a control, here Button9 being copied and assigned to be Button13.

So far, so good, but compiler says: Identifier not found "Button13"

The component window lists Button13

The control inspector shows Button13 and the event tab shows OnClick: Button13.Click

Unit1 shows in the type section the procedure: procedure Button13Click(Sender: TObject); - same in the implentation section.

???????

I just want to copy a selection of controls and having the controls listed without any code - so I can enter the correct code for the new controls - as it works with comparable other IDEs.

What am I doin wrong?

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: copy and paste:Identifier not found "Button13
« Reply #1 on: March 07, 2023, 11:37:53 am »
What is Lazarus and OS versions?

How do you copy Button9? What is the name of Button9's OnClick method?
If you copy button on a form to the same form or different form, Lazarus keeps same OnClick method, so this is strange what you are describing. I.e. if your Button9's OnClick method name is Button9Click, then after you copy button and it becomes Button13, OnClick method stays the same: Button9Click.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: copy and paste:Identifier not found "Button13
« Reply #2 on: March 07, 2023, 12:22:01 pm »
Which "comparable" IDE? I don't believe you.
Lazarus (and Delphi for that matter) plain works but NOT between instances.
Specialize a type, not a var.

pentilisea

  • Guest
Re: copy and paste:Identifier not found "Button13
« Reply #3 on: March 08, 2023, 10:34:58 am »
Lazarus 2.0.12
OS: MX Linux

Sorry for all the type errors ...

Several times I tried copy and paste controls, but due to what I experienced I rather add controls manually, which is time consuming...

Just doing it now.

So, when I copy a control, like a button23, captionn ot the new control goes up, button24, when I double click the old name is in inspector and the old procedure comes up: "TForm1.Button23Click(Sender: TObject);" with code. Then I do create an default event and the button23 procedure opens up again, in the type section button24 is listed, the procdure for button24 is not listed. The inspector shows button24 with no caption, because these buttons need to show no caption when running, however, I doubled this in code by writing "button24.caption ;= '';"

The inspector Event tab shows OnClick: Button23Click.

Now, I used to correct this as much as possible, but it does not work every time, so I delete the new button and create it new.

I'm lost for a solution, as the work becomes cumbersome. Maybe, because I put these buttons up without a caption?
Labels for example copy ok. So when I copy a button that has not caption in the inspector, but has a name provokes this behavior?

Also when copying the code of the control comes with it - that should not happen ....

Anyway, thanks for asking.

Klaus
« Last Edit: March 08, 2023, 10:45:22 am by pentilisea »

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: copy and paste:Identifier not found "Button13
« Reply #4 on: March 08, 2023, 10:56:06 am »
Also when copying the code of the control comes with it - that should not happen ....
Klaus, you have to understand that a simple copy operation on its own does not have enough context to succeed.
Specialize a type, not a var.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: copy and paste:Identifier not found "Button13
« Reply #5 on: March 08, 2023, 11:00:55 am »
When you copy and paste a control (Button23) all properties are copied to the copied control (Button24). The copied control will also have the event handlers of the original control, but you must be aware that these event handlers are not independent code, but point to the code of the original control.  So, when the original Button23 had an OnClick handler Button23Click, the new control will reuse the same code, i.e. it will not have its own event handler. This means that when you now double-click on Button24 it will open the Button23Click procedure - I am aware that this can lead to confusion because when you now edit Button23Click you will also change the OnClick handler of the original button... It is hard to say whether this is a bug or a feature because I can imagine that in many cases the user wants exactly the current behaviour: Copy a control and use the same event handlers.

If you don't want this, select "(none)" from the event dropdown list of the copied control first, and then click on the "..." to create a new empty event handler.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: copy and paste:Identifier not found "Button13
« Reply #6 on: March 08, 2023, 11:05:22 am »
@wp

That only works with a single instance, NOT with two projects open or multiple instances.

It would be a miracle if a copy operation like OP intended also created the resources necessary.
In this case the resources are not found because they do not exist in the context.
« Last Edit: March 08, 2023, 11:06:53 am by Thaddy »
Specialize a type, not a var.

pentilisea

  • Guest
Re: copy and paste:Identifier not found "Button13
« Reply #7 on: March 08, 2023, 06:56:35 pm »
Dear WP,
thanks a lot for the time to respond in length. I'm spolled by Gambas3 where a copied copntrol comes with nothing but a new Caption.
Seems I have to adapt.

Rergards,

Klaus

 

TinyPortal © 2005-2018