Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a function global to all project/or whole .cpp unit

Status
Not open for further replies.

pingLeeQuan

Programmer
Jul 3, 2002
45
US
i feel very humbled by asking this question and pardon me for asking such stupid one.

I have a class called DisplayDude(AnsiString DudeString). It is in the main class of the project.

I need to be able to call this function from within another function.

How can i make DisplayDude global to all the project so i can call it from anywhere instead of just calling it from the main .cpp unit?

thanks in advance
quan
 
Tha reason for using units is to make the code independent for other parts, but a way to make that thing possible is including the unit to each "unit" in your project.

for example,
you have the function in unit1
and to make refreence to this in unit2 is including unit.h in unit2 and calling something like this
Form1->anything...

I hope it helps

---LastCyborg---
 
Thanks LastCyborg, That also did not work. I understand what you are trying to tell me...

I broke it down to steps where i can diagnose it. My findings were that I cannot even call the function from WITHIN the same unit? I tried to put the function in the "public" section of the class but it did not like that at all.

I was able to call the function from the main body but not from a function in the main body

All i am trying to do now is call a function from within another function in the same unit. Even that does not work...

what is it that i am doing wrong?
thanks again
--quan
 
Then another way to make that possible is declaring your method "static"
like this

Class TYour_class
{
private:
public:
static AnsiString method_name();
};

AnsiString TYour_class::method_name()
{
//code for your method
return something;
}

and then in the main program (unit)
you can call it
ShowMessage( Your_class::method_name() );


Note that you have not to make an instance to make this possible

I hope that now it helps


---LastCyborg---
 
I think there is some confusion as to whether you are refering to a class or a function. I think you are refering to a function. If this is the case you can prototype your function outside of the main class as you are calling it and define it in the main form or unit. you can then use the extern keyword to call it from another unit


tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top