Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
Need a really simple answer to a simple question!!! Posted by James on 15 May 2000 at 11:15 PM
Hey, <br>
<br>
I've been programming a game for quiet some time now and have come across a bit of a problem.<br>
My code is too long for one pascal file and the error message says that I need to put some of the code into a unit.<br>
I understand how to use a unit and how to make one except I would love to know, how can I put code in the unit which has variables which apply to my main program?<br>
I hope I have asked this question clearly.<br>
Help would be greatly appreciated!!!<br>
<br>
Thanks in advance!


Edit Report
Re: Need a really simple answer to a simple question!!! Posted by steve on 16 May 2000 at 12:05 AM
try declaring the variables in the "interface" section.<br>
<br>
if you wanted to centralize such varable declararations<br>
you can have a unit that merely has these declarations,<br>
rather like a "block common", jhc I haven't used that<br>
term for years.


Edit Report
For Attention Steve: Posted by James on 17 May 2000 at 12:42 AM
Hey Steve,<br>
<br>
Please could you explain clearly how I can have variables in my main program and have them active in the unit. See the thing is, when I put them under the "interface" section it takes them as variables but they don't keep their value from the main program.<br>
See in the unit I want to put in code which draws images to the screen using co-ordinates that are defined and changed constantly in the main program as objects are moved around.<br>
So the unit has to use the exact variables declared in the main program.<br>
<br>
P.S. I'm not an expert programmer, maby because I'm actually still at school and everything I know about programming I taught myself, so please forgive me for seeming a bit "daaa". Soo maby an example would be great! if you know how.<br>
<br>
Thanks a lot!<br>



Edit Report
Re: For Attention Steve: Posted by The Watcher^TUHB on 17 May 2000 at 3:54 AM
Just do it like this<br>
<br>
Unit unitname<br>
<br>
interface<br>
variablename:integer;<br>
<br>
implementation<br>
end.<br>
<br>
<br>
and now REMOVE the variable declaration from your main program. If you main program now does a <br>
<br>
USES unitname <br>
<br>
you can just use the variables the same way as you would when they were in your main. You can also change them from your main and all. Just be sure to declare the variable ONLY in your unit, and not both in your unit and the main program.<br>
<br>
And oh, we could tell that you are not a cutting-edge programmer, for else you wouldn't have crammed over 64k of code in your main <br>



Edit Report
Cheers Mate! Posted by James on 17 May 2000 at 11:04 AM
Thanks alot MR smartie pants!<br>
No seriously, thanks!<br>
<br>
I'll be back for more questions.<br>
But for now I'm kewl!<br>
<br>
Oh, P.S. Does anyone know how to play mid files in the background while a program is running?<br>
I'm guessing it's complicated?<br>
So I wouldn't know how...but if anyone has an easy to use unit that they wanna share?<br>
Just give me a shout.<br>
<br>
Thanks all<br>
Later!





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.