Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search function

Status
Not open for further replies.

Mobiu5

Programmer
Oct 11, 2009
1
CA
I am trying to modify my application to make adding modules easier. Currently, all modules are hard coded in my program, so when I want to add something, I have to release a new version.

Here is what I want it to do for me.

Each module has its own directory found in folder modules. In each folder is a file with the extension "nrd".

Program
-Modules
--mod1
--mod1.nrd
--mod2
--mod2.nrd
--mod3
--mod3.nrd

What I want is my program to scan my modules folders sub directories for the .nrd file automatically when my frame is entered (no button to activate the procedure). When completed, I need it to put it in a list, where I will run processes from there depending on the modules that are found.

Here is the code that I am using, but it does not seem to compile with errors

[ERRORS]
[Warning] Unit96.pas(7): W1005 Unit 'FileCtrl' is specific to a platform
[Error] Unit96.pas(96): E2010 Incompatible types: 'TStringList' and 'string'
[Error] Unit96.pas(96): E2010 Incompatible types: 'string' and 'Boolean'


Code:
procedure FindFiles(FilesList: TStringList; StartDir, FileMask: string);
var
  SR: TSearchRec;
  DirList: TStringList;
  IsFound: Boolean;
  i: integer;
begin
  if StartDir[length(StartDir)] <> '\' then
    StartDir := StartDir + '\';

  { Build a list of the files in directory StartDir
     (not the directories!)                         }

  IsFound :=
    FindFirst(StartDir+FileMask, faAnyFile-faDirectory, SR) = 0;
  while IsFound do begin
    FilesList.Add(StartDir + SR.Name);
    IsFound := FindNext(SR) = 0;
  end;
  FindClose(SR);

  // Build a list of subdirectories
  DirList := TStringList.Create;
  IsFound := FindFirst(StartDir+'*.nrd', faAnyFile, SR) = 0;
  while IsFound do begin
    if ((SR.Attr and faDirectory) <> 0) and
         (SR.Name[1] <> '.') then
      DirList.Add(StartDir + SR.Name);
    IsFound := FindNext(SR) = 0;
  end;
  FindClose(SR);

  // Scan the list of subdirectories
  for i := 0 to DirList.Count - 1 do
    FindFiles(FilesList, DirList[i], FileMask);

  DirList.Free;
end;

procedure TForm96.FrameEnter(Sender: TObject);

var
  FilesList: TStringList;
    FileMask: String;
begin
  FilesList := TStringList.Create;
  try
    FindFiles(GL_SYSTEMROOT+GL_Local_Main+GL_Local_ModDir, '*.nrd', true);
    ListBox1.Items.Assign(FilesList);
    lblNumberFound.Caption := 'Modules found: ' + IntToStr(FilesList.Count);
  finally
    FilesList.Free;
  end;
 
You would do well to not necessarily post so much code and just post what you are unsure about. Also, you would do well to indicate precisely what you are looking for in making a post. Are you not sure how to solve the compiler errors? Or is it something different? And if it is indeed the compiler errors, you would do well to indicate the lines of code that the compiler is indicating to be in error.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top