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'
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;