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


   
Amanda77Asked:
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.

pvlierCommented:
How do you call the function and how is it written? Here's an example how it should work: http://www.daniweb.com/forums/thread143363.html
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.
0
ebob42Commented:
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
interface

procedure SendMall;

implementation

procedure SendMail;
begin
// ...
end;

end.

Open in new window

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

Type
 TForm1=class(TForm)
...
 public
   procedure SendEmail(SendTo,Subject,Body:String);
 end;

Var
 Form1:TForm1;

// 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
Form1:=TForm1.Create(Application.MainForm);
// or in your project main source code
Application.CreateForm(TForm1, Form1);  


and you called from your unit :

TForm1.SendEmail('you@mail.com','test','email test');

instead of

Form1.SendEmail('you@mail.com','test','email test');
0

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
0
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
Delphi

From novice to tech pro — start learning today.