33 Votes

Delphi: This form of method call only allowed for class methods

Question by Guest | Last update on 2022-07-27 | Created on 2012-09-07

I have two units in Delphi, each corresponding to a window in my program. In the first window, I defined a procedure, that I would like to call in the second window.

My first approach to call the procedure was the following:

MyProcedure(Sender);

However, with this approach, Delphi could not find the procedure, so I thought, I have to precede the name of the form to tell Delphi where the procedure is defined:

TForm1.MyProcedure(Sender);

However, this approach also does not do it. The program compiles, but when you open the program, the following error message occurs, with which I can not do anything:

This form of method call only allowed for class methods

I have already tried to define the procedure in the public section and such things, but it just is not working. Can someone help me?

ReplyPositiveNegative
3Best Answer3 Votes

TForm1 is only the type, something like a description of how your form looks like. Therefore, you can not call a procedure from this construction plan.

Try it with the following approach:

Form1.MyProcedure(Sender);

Somewhere at the beginning of your unit, there is written "Form1: TForm1". This means, that "Form1" is of the type "TForm1". And therefore, procedures can only be called from "Form1", not "TForm1".
Last update on 2022-07-27 | Created on 2012-09-09

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.