User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 455,982 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 2760 | Replies: 30
Reply
Join Date: Nov 2007
Posts: 44
Reputation: Loyen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Loyen Loyen is offline Offline
Light Poster

How to get Dev-Pascal to use other files?

  #1  
Nov 29th, 2007
Hi, simple question but maybe with an advanced answer:
How do I get Dev-Pascal to read other files?

Example
I've tried to make a variable and make it as a text for example (var test:text and then assign(text,'textfile.txt'); but then I want pascal to read it and open it in the console and print out the text on the screen.

This is not the only thing I wanted to test. I want to try to make other files like pictures, textfiles and all to be opened by pressing on the exe file. Like everytime i press that *exe file all the files I've written in it will be opened.

Dunno if it works, just asking, and hopefully getting ansers.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to get Dev-Pascal to use other files?

  #2  
Nov 29th, 2007
Er, you are using FreePascal as the compiler, right? (Not GNU Pascal?)

To open a text file, and print every line in it prefixed by the line number:
  1. {$I-}
  2. var
  3. t: textFile;
  4. s: string;
  5. i: integer;
  6. begin
  7. assignFile( t, 'fooey.txt' );
  8. reset( t );
  9. if IOResult <> 0 then
  10. begin
  11. writeln( 'fooey' );
  12. halt( 1 )
  13. end;
  14.  
  15. i := 1;
  16. readln( t, s );
  17. while not eof( t ) do
  18. begin
  19. writeln( 'line ', i, ': ', s );
  20. readln( t, s );
  21. inc( i )
  22. end;
  23.  
  24. closeFile( t )
  25. end.

If you are using GNU Pascal I think you can still use the above, but GPC tends toward the Extended Pascal syntax, which means that external file variables must be declared as bindable, and opened using different routines than reset and closeFile.

Hope this helps.
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Loyen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Loyen Loyen is offline Offline
Light Poster

Re: How to get Dev-Pascal to use other files?

  #3  
Nov 29th, 2007
it's Blodsheet Dev Gnu-Pascal. it won't work, had to delete closefile and change string to char cause this was the error I got:

c:\documents and settings\07patrik\skrivbord\untitled1.pas:4: warning: missing string capacity - assuming 255
c:\documents and settings\07patrik\skrivbord\untitled1.pas: In main program:
c:\documents and settings\07patrik\skrivbord\untitled1.pas:21: undeclared identifier `Closefile' (first use in this routine)
c:\documents and settings\07patrik\skrivbord\untitled1.pas:21: (Each undeclared identifier is reported only once
c:\documents and settings\07patrik\skrivbord\untitled1.pas:21: for each routine it appears in.)

And when I've changed string to char (just to test so it works) and deleted closefile it popups for.. 0,5seconds.. :/ like it did before when I tested the first thing I wrote (top)
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to get Dev-Pascal to use other files?

  #4  
Nov 29th, 2007
(Sorry to respond so late. Dinner called.)

But it didn't complain about "reset"? Sounds like you are using BORLAND mode.
I used an Object Pascal thing, sorry:

instead of "assignFile" say "assign"
instead of "closeFile" say "close"

And make sure you give your string a length
var s: string[ 255];

If this stuff doesn't work then you are using ISO Pascal mode, and handling files is entirely different. Let me know.
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Loyen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Loyen Loyen is offline Offline
Light Poster

Re: How to get Dev-Pascal to use other files?

  #5  
Dec 3rd, 2007
no problem.. I can't get it to work.. I have made like my posted program above, then changed "assignfile" and "closefile" to "assign" and "close".. now it popups.. but goes away directly after it comes up, like if you just make a problem like "hello world" without a readln at the end.. any more help?
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to get Dev-Pascal to use other files?

  #6  
Dec 3rd, 2007
Sounds like the Dev IDE is too stupid to realize that you have made a console program. I refuse to use Bloodshed anything, so I don't know anything about the program, but there should be something in there to keep the console visible. Poke around the menus and see if you can find it.

The other option is just to add
  1. write( 'Please press ENTER to quit.' ); readln
to the end of your program (just before the end. statement). The analogy to Hello World is exactly right --the same thing is happening.

Hope this helps.
Last edited by Duoas : Dec 3rd, 2007 at 3:17 pm.
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Loyen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Loyen Loyen is offline Offline
Light Poster

Re: How to get Dev-Pascal to use other files?

  #7  
Jan 31st, 2008
Well, it still won't work. (I'm not so often on this site so It can take a few days before coming back, sorry for that, will try to update myself earlier).

It won't open the txt file. Where should the txt be putted anyway? I putted it in the same directory as the exe and with the name as entered in pascal.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to get Dev-Pascal to use other files?

  #8  
Jan 31st, 2008
Post your code and I'll take a look at it.
Reply With Quote  
Join Date: Nov 2007
Posts: 44
Reputation: Loyen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Loyen Loyen is offline Offline
Light Poster

Re: How to get Dev-Pascal to use other files?

  #9  
Jan 31st, 2008
program Untitled;
var
t: text;
s: string[255];
i: integer;
begin
assign( t, 'untitled.txt' );
reset( t );
if IOResult <> 0 then
begin
writeln( 'untitled' );
halt( 1 )
end;

i := 1;
readln( t, s );
while not eof( t ) do
begin
writeln( 'line ', i, ': ', s );
readln( t, s );
inc( i )
end;

close( t )
end.


(don't remember the pascal code for easier reading)

It just pops up a window in the console REALLY fast, and I can read "untitled" in it. but I want to open the txt file in the "assigned application" (for the file, default program to open the file format)
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: How to get Dev-Pascal to use other files?

  #10  
Jan 31st, 2008
I compiled and executed your program with FreePascal 2.2, Delphi 5, and Turbo Pascal 4 and it works just fine for me.

The file "untitled.txt" should be in the same directory as the exe.

It is possible that the IDE is running your program in the wrong directory. Try executing it from the command line.

Hope this helps.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 9:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC