Execute similar tasks with different configuration
tmvishnu 29 Dec 2008 06:28
Here is a method you can use to to automate a similar kind of tasks using different configurations.
Here is an example of a configuration file.
[PROJECT_NAME]
Project A
[PROJECT_PATH]
C:\projects\project-a\resources\
[PROJECT_RESOURCES]
"0001", "ITEM1-1", "ITEM1-2"
"0002", "ITEM2-1", "ITEM2-2"
"0003", "ITEM3-1", "ITEM3-2"
"0004", "ITEM4-1", "ITEM4-2"
Here is what you have to do:
Use the GetSection function to read the sections in the configuration file:
Example:
var
doc: string
i: integer;
ProjectPath, ProjectResource, ProjectName: string;
FileList: TStringList;
Output: TStringList;
begin
doc := document.text;
FileList := TStringList.create;
Output := TStringList.create;
// returns the project name 'Project A'
ProjectName := GetSection(doc, '[PROJECT_NAME]');
// returns the project path
ProjectPath := GetSection(doc, '[PROJECT_PATH]');
// returns the project resource list
// (you may need to use comma deliminated text handling to read
// the items in the list)
ProjectResource := GetSection(doc, '[PROJECT_RESOURCES]');
// read files from the path to process them
FileList.Text := LoadFilesByMask(ProjectPath, '*.csv');
for i := 0 to FileList.count-1 do
begin
// do something using ProjectName, ProjectResource, etc ....
Output.Add('add the output items here....');
end;
// this will display the output list in a new window.
writeln(Output.Text);
FileList.free;
Output.Free;
end.
Place this action code into the Command Toolbar for execution. Open as many document with different configurations to execute them based on the respective configuration file.
Hope it helps.