Recent

Author Topic: [SOLVED] Help to understand how Procedure names affect IDE  (Read 4605 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
[SOLVED] Help to understand how Procedure names affect IDE
« on: July 22, 2011, 11:05:32 pm »
While in the IDE,
I create a TButton, I call it, say, ButtonX. Its caption can be anything.

Then I click twice on ButtonX and it declares a procedure in the Type section, under TForm1= CLASS(TForm),  called procedure ButtonXClick(Sender: TObject); This makes sense, no problem.

Also, a skeleton is constructed automatically for the procedure called
TForm1.ButtonXClick(Sender: TObject);...Then I put some code so it does whatever.

It's all fine to here.

But if I want to change the name of the procedure so that it does not have the term Click, and so it only be called "Procedure ButtonX", I do that by going to the design form and in ButtonX properties, EVENTS, I change the name of the event DELETING THE "Click" part of the name, which it allows.

Now, automatically, in the Editor, the code is all changed to reflect the RENAMING of the EVENT for the button.

So actually ALL THE TOTAL change when all is working, consists of CHANGING the name of the event (in this case deleting "Click" from the event name. So the code is actually automaticallyupdated correctly to reflect this.

HOWEVER, when then I click the green arrow to RUN the program, I get this error message: Overload Identifier ButtonX isn't a function.

In summary, changing the name so the event is no longer called ButtonXClick, to just ButtonX creates this strange response.

And so I'd still like to know why, because I'd still like to change the name of the event so it does not have the name click. I have reasons for this wanting, and this here is just example. Actual component names would vary, of course.

Thanks for any help.


 
« Last Edit: July 22, 2011, 11:12:06 pm by Elmug »

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Help to understand how Procedure names affect IDE
« Reply #1 on: July 22, 2011, 11:11:35 pm »
OK, sorry, I sorted it out.

The renaming is NO PROBLEM, except that the name I gave to the Event is also the identifier of the component itself.

I just renamed it to ButtonXwhatever and all works fine.

I did not realize that the (event name) can not be the same name as the name of the object that owns the event.

I'll leave the thread in case this happens to another person.

Thanks!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12209
  • Debugger - SynEdit - and more
    • wiki
Re: Help to understand how Procedure names affect IDE
« Reply #2 on: July 22, 2011, 11:14:54 pm »
You can rename it, but you can not rename it to be the same name as the buttons name.

If you make it having the same name, then in your form you  have:

Code: [Select]
TForm1 = class
  ButtonX: TButton;
private
  procedure ButtonX(Sender: TButton);
end;

So the identifier "ButtonX" is ambigious. It means the procedure, but it also means the variable.

If the compiler then in your code finds ButtonX, it doesn't necessarily know what you meant.
To avoid that the compiler does not allow this at all.

You can name your procedure BtnX or anything you want. So long as it isn't used yet.

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: [SOLVED] Help to understand how Procedure names affect IDE
« Reply #3 on: July 22, 2011, 11:34:45 pm »
Right, Martin.

And since I insisted on having the name of the event be WhatIWant, I actually chose to slightly rename first the component (the button) and then I changed the name of the event, WHICH of course becomes the name of the procedure in the code, and is where I want a certain readability to suit my thinking, as far as to what the name of the procedure is when I call it.

Also, I suppose the name of the event CAN NOT be the name of another object (button) or whatever.

And, I don't recall that the change ever put the word "function" anywhere, even though the error message used the word "function", but i am not sure now.

Thanks!
« Last Edit: July 22, 2011, 11:36:47 pm by Elmug »

 

TinyPortal © 2005-2018