Read entire file: Difference between revisions
→{{header|FutureBasic}}
(→{{header|Prolog}}: Adding Prolog) |
|||
Line 837:
=={{header|FutureBasic}}==
Note: This code goes beyond simply specifying the file to open. It includes a dialog window (openpanel) that allows the user to select a text file to read. Depending on system memory, as many as 4.2 billion characters can be read. The file contents are placed in a convenient
<lang futurebasic>_window = 1▼
begin enum 1
_scrollView
_textView
void local fn BuildWindow
▲Note: This code goes beyond simply specifying the file to open. It includes a dialog window that allows the user to select a text file to read. Depending on system memory, as many as 4.2 billion characters can be read. The file contents are placed in a convenient console window with automatic save as, copy and paste, select all and undo commands. (Did I mention that FutureBasic -- or FB as developers prefer to call it -- is handy for Macintosh development!) Of course, the programmer is free to code his own window and menu options.
CGRect r = {0,0,550,400}
▲<lang futurebasic>
window _window, @"Read Entire File", r
scrollview _scrollView, r
ViewSetAutoresizingMask( _scrollView, NSViewWidthSizable + NSViewHeightSizable )
textview _textView,, _scrollView
end fn
local fn ReadTextFile
CFStringRef string
CFURLRef url = openpanel 1, @"Select text file..."
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
TextSetString( _textView, string )
else▼
▲ if ( h )
▲ end if
▲else
▲end if
end fn
fn BuildWindow
fn ReadTextFile
HandleEvents</lang>
This can be shortened considerably by wrapping Objective-C code:
<pre>
|