Recent

Author Topic: How should i use unit2 to get access to function from unit1  (Read 5196 times)

seba22

  • Full Member
  • ***
  • Posts: 136
How should i use unit2 to get access to function from unit1
« on: December 18, 2010, 10:08:24 pm »
Welcome,

I have unit1.pas, whats my main program.

I want cleanup my code and put some functions into separated file.

I created unit2.


In unit1, at uses i add unit2.


Inside unit2 i have created function.



Problem is, when i want access in this function, other function what i have inside unit1.

I had try, write in uses of unit2  (unit1) but it says its duplicated and i cant do it, because i run this unit from main.

Inside unit1, i add  header of my function into pubilc declarations.

So i think it should be visible from unit2.

For test, i add into public varialbe test:string;

and i use this variable from unit2.
(succesfully compiled)

But why i can't run this function ?


Regards

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How should i use unit2 to get access to function from unit1
« Reply #1 on: December 18, 2010, 10:12:56 pm »
You need to add Unit1 to uses section of Unit2, but do it like this:

Code: [Select]
implementation

uses unit1; 

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How should i use unit2 to get access to function from unit1
« Reply #2 on: December 19, 2010, 08:36:21 am »
This is often asked, probably no. 2 top questions. Should this be included in the FAQ?

seba22

  • Full Member
  • ***
  • Posts: 136
Re: How should i use unit2 to get access to function from unit1
« Reply #3 on: December 19, 2010, 10:57:00 am »
Welcome,
Thank you.

I was trying to put it into uses at top and that cause problem.

Don't be angry for me, but i think it will be nice to write somewhere little tutorial helping understand how do this.

I know that is easy, now i know how to do this but at first time it was it's complicated.
I can't find any easy example what cover only this topic.

Thank You ;)
Regards

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How should i use unit2 to get access to function from unit1
« Reply #4 on: December 19, 2010, 11:55:02 am »
I add an entry for this in the FAQ, hope this kind of question will not be asked anymore (or at least decreased) in the future.

@seba32:
No, I wasn't angry :D

 

TinyPortal © 2005-2018