Mega Code Archive

 
Categories / Delphi / Examples
 

Findfirst

var {public} TABfileList: TStrings; OUTfileList: TStrings; IMGfileList: TStrings; end; procedure TMainForm.FormCreate(Sender: TObject); begin TABfileList := TStringList.Create; OUTfileList := TStringList.Create; IMGfileList := TStringList.Create; dataFilesOK := GetCNSVTYDataFilenames; end; function TMainForm.GetCNSVTYDataFilenames: Boolean; {get the names of all sets of three data files that are associated with each 'conservatory module' on startup here, prior to loading data from the files and drawing one or more existing 'conservatory modules' on the startup screen} var SearchRec: TSearchRec; tempDirPath: String; tempString: String; allPresent: Boolean; begin allPresent := True; {get data from the ..\DATA\STYLES directory here...} tempDirpath := exeFilepath + StylesDataDir + '*.TAB'; FindFirst(tempDirPath, faAnyFile, Searchrec); if (not(Searchrec.Name = '')) then TABfileList.Append(SearchRec.Name); while (FindNext(SearchRec) = 0) do begin TABfileList.Append(SearchRec.Name) end; if (not(Searchrec.Name = '')) then TABfileList.Append(SearchRec.Name); FindClose(SearchRec); if (TABfileList.Count = 0) then begin tempString := 'Cannot find ' + tempDirPath; Application.MessageBox(PChar(tempString), ' Missing Data Files', mb_OK); allPresent := False; end else allPresent := True; {in each of the sections below we get data from the subdirectories below the MODULES directory...} tempDirpath := exeFilepath + TablesDataDir + '*.TAB'; FindFirst(tempDirPath, faAnyFile, Searchrec); if (not(Searchrec.Name = '')) then TAB2fileList.Append(SearchRec.Name); while (FindNext(SearchRec) = 0) do begin TAB2fileList.Append(SearchRec.Name) end; if (not(Searchrec.Name = '')) then TAB2fileList.Append(SearchRec.Name); FindClose(SearchRec); if (TAB2fileList.Count = 0) then begin tempString := 'Cannot find ' + tempDirPath; Application.MessageBox(PChar(tempString), ' Missing Data Files', mb_OK); allPresent := False; end else allPresent := True; tempDirpath := exeFilepath + 'MODULES\OUTLINES\*.OUT'; FindFirst(tempDirPath, faAnyFile, Searchrec); if (not(Searchrec.Name = '')) then OUTfileList.Append(SearchRec.Name); while (FindNext(SearchRec) = 0) do begin OUTfileList.Append(SearchRec.Name) end; if (not(Searchrec.Name = '')) then OUTfileList.Append(SearchRec.Name); FindClose(SearchRec); if (OUTfileList.Count = 0) then begin tempString := 'Cannot find ' + tempDirPath; Application.MessageBox(PChar(tempString), ' Missing Data Files', mb_OK); allPresent := False; end else allPresent := True; tempDirpath := exeFilepath + 'MODULES\IMAGES\*.IMG'; FindFirst(tempDirPath, faAnyFile, Searchrec); if (not(Searchrec.Name = '')) then IMGfileList.Append(SearchRec.Name); while (FindNext(SearchRec) = 0) do begin IMGfileList.Append(SearchRec.Name) end; if (not(Searchrec.Name = '')) then IMGfileList.Append(SearchRec.Name); FindClose(SearchRec); if (IMGfileList.Count = 0) then begin tempString := 'Cannot find ' + tempDirPath; Application.MessageBox(PChar(tempString), ' Missing Data Files', mb_OK); allPresent := False; end else allPresent := True; Result := allPresent; end; procedure TMainForm.FormDestroy(Sender: TObject); begin TABfileList.Free; OUTfileList.Free; IMGfileList.Free; end;