call function from another unit

Dear Experts
 I have a function "SendEmail" that will be used in all my units.pas and I want to write that function only one time and call it from all the units, what should I do?

I tried  to put sendmail.pas in the uses statement in the calling unit but I got this error
"This form of method call only allowed for class methods"
thank you

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How do you call the function and how is it written? Here's an example how it should work:
if it still doesn't work the put a (simplified) version of your units online for us to see.... Maybe you are trying to call units.SendEmail or have you function placed inside a form or something.
You probably add the method SendMail to a form or other class, and then try to call it directly without constructing the class.

Here's an example of a unit called Unit1, defining SendMail. Any other unit can put Unit1 in the uses clause and call the SendMail global function.
unit Unit1; // in unit1.pas

procedure SendMall;


procedure SendMail;
// ...


Open in new window

Emmanuel PASQUIERFreelance Project ManagerCommented:
you have called it from the class instead of from the instance (variable)
Your unit is like this :

   procedure SendEmail(SendTo,Subject,Body:String);


// Form1 is the variable containing the instance, TForm1 is the class.
// the instance is created with Create and stored in the variable somewhere in your application
// or in your project main source code
Application.CreateForm(TForm1, Form1);  

and you called from your unit :

TForm1.SendEmail('','test','email test');

instead of

Form1.SendEmail('','test','email test');

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amanda77Author Commented:
thank you very much
that is exactly where I was mistaken...I guess I don't know that much about classes and instances
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.