home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
TOT11.ZIP
/
TOTDOC11.ZIP
/
CHAPT10.TXT
< prev
next >
Wrap
Text File
|
1991-02-11
|
28KB
|
723 lines
Displaying
Directories
"An intellectual is someone who can listen to the William Tell overture
and not think of the Lone Ranger."
Anonymous
The Toolkit includes two entirely different object families for dis-
playing directory listings. The objects ListDirOBJ and ListDirSortOBJ
are descendant from ListOBJ and should be used when you want to display
the directory in a stretchable window, or let the user select multiple
files. The DirWinOBJ should be used when you want to display a file
selection dialog box and allow the user to choose a single file.
Displaying Directory List Windows
The totLIST unit includes the ListDirOBJ object which is an adaptation
of ListOBJ. ListDirOBJ is designed to display files and directories in
a stretchable window. ListDirOBJ is a descendant of ListOBJ, and inher-
its all the following ListOBJ methods:
Init
SetTopPick
SetActivePick
SetTagging
SetColWidth
Show
Go
LastKey
GetHiString
Win^
Done
Some of the list defaults are influenced by LookTOT^ methods. Refer
back to page 9-20 for a full description of these methods.
In addition to the inherited methods, ListDirOBJ includes the following
important method:
ReadFiles(Filemasks:string; FileAttrib:word);
This method must be called before the Go method. ReadFiles instructs
the object to read all the files matching the first parameter. The
filemask should include wild cards, e.g. *.pas, *.*, bob?.tit, etc.,
and may optionally include a drive and path. If a drive/path is not
specified, all matching files in the default directory will be read.
Note that the string may include more than one file specification sepa-
rated by spaces, e.g. '*.pas *.asm'. The second parameter identifies
the attributes of the files to include in the list.
10-2 User's Guide
--------------------------------------------------------------------------------
The Turbo Pascal DOS unit includes the following file attribute con-
stants:
ReadOnly = $01
Hidden = $02
SysFile = $04
VolumeID = $08
Directory = $10
Archive = $20
AnyFile = $3F
Specify any of the desired file types by summing these constants and
passing them as the second parameter. For example, the following method
call will list all the .TXT files that can be edited:
ReadFiles('*.TXT',Anyfile-ReadOnly-Hidden);
Note that the Toolkit automatically removes the VolumeID file from the
list.
In summary, to display a basic file listing, all you have to do is
declare an instance of ListDirOBJ, and then call the methods Init,
ReadFiles and Go. The chosen file can be determined by calling the
function method GetHiString. Listed below is the demo file DEMDR1.PAS
which displays a simple directory, followed by figure 10.1 showing the
resultant list.
program DemoDirectoryOne;
{demdr1 - the default directory list}
Uses DOS, CRT,
totFAST, totLIST;
Var
ListWin: ListDirObj;
begin
Screen.Clear(white,'░'); {paint the screen}
with ListWin do
begin
Init;
ReadFiles('*.*',AnyFile);
Go;
Win^.Remove;
if (LastKey = 27) or (Lastkey = 600) then
writeln('You escaped!')
Else
writeln('You chose file '+GetHiString);
Done;
end;
end.
Displaying Directories 10-3
--------------------------------------------------------------------------------
Figure 10.1 [SCREEN]
A Basic Directory
List
Determining Tagged Files
By default, the user can select multiple files by hitting the [KEYCAP]
or clicking the left mouse button on a filename. The method SetTagging
can be used to enable or disable multiple file tagging.
The ListDirOBJ object implements the methods GetStatus and SetStatus to
provide access to tagged files. These methods work in precisely the
same way as their namesakes in the DLLOBJ family. Full descriptions can
be found on page 9-27, but in brief, GetStatus returns a boolean to
indicate whether the file has been tagged, and is passed two parame-
ters; the first parameter is the number of the file in the list, and
the second is the flag ID which should be set to 0 (zero) to check the
status of the tag flag.
Each ListDirOBJ instance includes a FileDLLOBJ object which is a linked
list holding all the file details. The ListDirOBJ object provides the
method FileList which returns a pointer to the FileDLLOBJ list. This is
useful when you want to directly manipulate the file linked list. You
may recall that all DLLOBJ objects have a method TotalNodes which
returns a longint identifying the number of entries in the list. The
ListDirOBJ method FileList^.TotalNodes therefore returns the total num-
ber of files in the list.
The demo program DEMDR2.PAS, listed below, shows how the methods GetS-
tatus and FileList^.TotalFiles can be used to ascertain which files the
user tagged. Notice that you must access the tagged files before
calling the method Done - otherwise, the list will be disposed of
before you can access it! Following the listing are figures 10.2 and
10.3 which provide an example of the output generated by the program.
Note that the highlighted file will only be included in the list if the
file is tagged.
program DemoDirectoryTwo;
{demdr2 - determining chosen files}
Uses DOS, CRT,
totFAST, totLIST;
Var
ListWin: ListDirObj;
Tot,L:longint;
begin
Screen.Clear(white,'░'); {paint the screen}
with ListWin do
begin
10-4 User's Guide
--------------------------------------------------------------------------------
Init;
ReadFiles('*.*',AnyFile);
Go;
Win^.Remove;
if (LastKey = 27) or (Lastkey = 600) then
writeln('You escaped!')
Else
begin
writeln('The highlighted file was '+GetHiString);
writeln('The tagged files were: ');
Tot := FileList^.TotalNodes;
for L := 1 to Tot do
if GetStatus(L,0) then
writeln(GetString(L,0,0));
end;
Done;
end;
end.
Figure 10.2 [SCREEN]
Tagging Multiple
Files
Figure 10.3 [SCREEN]
Di