home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: DEMOBASE }
-
- { Allows you to iterate through a table that
- lists all the programs that ship with Delphi
- Unleashed. If there is a description for the
- program, you can view it.
-
- This program can rebuild the ALLDIRS.DBF table
- at any time. To do so, just choose RELOAD from
- the menu. Note that at this time the path from
- which you want to start building the list is
- hardcoded into the ReLoadClick method.
-
- The program gets the descriptions by reading any
- text found at the top of the MAIN.PAS file for
- a project. If there is no MAIN.PAS file, then
- this program will not retrieve a description
- for the progrect. The algorithm for getting the
- description first searches for a file called
- MAIN.PAS. If there is one, then it opens it
- as a text file, skips one line, and reads in
- everything up until the interface.
- }
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs,
- Messages, Classes, Graphics,
- Controls, Forms, Dialogs,
- StdCtrls, DB, DBTables,
- DBCtrls, Grids, DBGrids,
- AllDirs, Fileiter, Menus,
- ExtCtrls;
-
- type
- TForm1 = class(TForm)
- DataSource1: TDataSource;
- DBGrid1: TDBGrid;
- DBMemo1: TDBMemo;
- Table1: TTable;
- FileIterator1: TFileIterator;
- Database1: TDatabase;
- MainMenu1: TMainMenu;
- Options1: TMenuItem;
- Count1: TMenuItem;
- N1: TMenuItem;
- ReLoad1: TMenuItem;
- Search1: TMenuItem;
- Indexes1: TMenuItem;
- None1: TMenuItem;
- Programs1: TMenuItem;
- Chapters1: TMenuItem;
- Panel1: TPanel;
- DBNavigator1: TDBNavigator;
- procedure CountClick(Sender: TObject);
- procedure FileIterator1FoundFile(FileName: String; SR: TSearchRec);
- procedure FormCreate(Sender: TObject);
- procedure ReLoad1Click(Sender: TObject);
- procedure Search1Click(Sender: TObject);
- procedure Indexes1Click(Sender: TObject);
- private
- procedure GetComments(FileName: string);
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- StrBox;
-
- {$R *.DFM}
-
- procedure TForm1.CountClick(Sender: TObject);
- var
- i: Integer;
- B: TBookmark;
- begin
- B := Table1.GetBookmark;
- i := 0;
- DataSource1.Enabled := False;
- Table1.First;
- while not Table1.EOF do begin
- Table1.Next;
- Inc(i);
- end;
- Table1.GotoBookmark(B);
- Table1.FreeBookmark(B);
- DataSource1.Enabled := True;
- MessageDlg('Total: ' + IntToStr(i), mtInformation, [mbok], 0);
- end;
-
- procedure TForm1.GetComments(FileName: string);
- var
- F: System.Text;
- FName, S: string;
- Done: Boolean;
- begin
- Done := False;
- FName := ExtractFilePath(FileName);
- FName := FName + '\main.pas';
- if not FileExists(FName) then exit;
- System.Assign(F, FName);
- System.Reset(F);
- ReadLn(F, S);
- while (not Done) and (not EOF(F)) do begin
- ReadLn(F, S);
- if Pos('interface', S) = 0 then
- dbMemo1.Lines.Add(S)
- else
- Done := True;
- end;
- System.Close(F);
- end;
-
- procedure TForm1.FileIterator1FoundFile(FileName: String; SR: TSearchRec);
- var
- ChapName, S: string;
- begin
- Table1.Insert;
- Table1.FieldByName('Program').AsString := UpperCase(ExtractFileName(FileName));
- S := ExtractFilePath(FileName);
- S := Shorten(S, 1);
- S := StripLastToken(S, '\');
- ChapName := GetLastToken(S, '\');
- Table1.FieldByName('Chapter').AsString := ChapName;
- GetComments(FileName);
- Table1.Post;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Table1.Open;
- end;
-
- procedure TForm1.ReLoad1Click(Sender: TObject);
- var
- S: string;
- begin
- S := 'This option deletes all current entries and rebuilds the listings.';
- S := S + 'Don''t choose this option unless you sure you know what you''re doing.';
- if MessageDlg(S, mtConfirmation, [mbOk, mbCancel], 0) = id_Cancel then Exit;
- Table1.EmptyTable;
- FileIterator1.Run('*.dpr', 'c:\unleash');
- end;
-
- procedure TForm1.Search1Click(Sender: TObject);
- var
- S: string;
- begin
- S := '';
- if not InputQuery('Program Name', 'Enter name: ', S) then Exit;
- Table1.IndexName := 'PROG_NDX';
- Table1.SetKey;
- Table1.FieldByName('Program').AsString := UpperCase(S);
- Table1.GotoNearest;
- end;
-
- procedure TForm1.Indexes1Click(Sender: TObject);
- const
- inNone = 100;
- inPrograms = 101;
- inChapters = 102;
- begin
- case (Sender as TMenuItem).Tag of
- inNone: Table1.IndexName := '';
- inPrograms: Table1.IndexName := 'PROG_NDX';
- inChapters: Table1.IndexName := 'CHAP_NDX';
- end;
- end;
-
- end.
-