...Build Resources from files located in a Directory?
Author: Max Kleiner
{
We want to get an output like this in a *.res format:
BMP1 BITMAP "bmp1ueli.bmp"
BMP2 BITMAP "bmp2uml.bmp"
BMP3 BITMAP "bmp3.bmp"
.....
1. We put all the files in a directory
2. We start the scriptResourceFile() procedure
   gets all the files like *.bmp or *.wav in a *.rc format
3. Activate the resource-compiler
}
procedure TStatForm.scriptresourceFile2(restype: string);
var
  f: textfile;
  ResFile: ShortString;
  resstr: string;
  s: array[0..2048] of Char;
  i, filecount: Byte;
  myResList: TStringList;
begin
  myresList := TStringList.Create;
  filecount := getfilelist(myResList);
  if filecount > totalPictures then
    filecount := totalPictures;
  for i := 0 to filecount - 1 do 
  begin
    resstr := Format('%s%d %s %s%s%s',
      ['bmp', i, restype, '"', myReslist.Strings[i], '"']);
    StrCat(s, PChar(resstr));
    StrCat(s, #13#10);
  end;
  ResFile := 'membmp.rc';
  AssignFile(f, ResFile);
  Rewrite(f);
  Write(f, s);
  closefile(f);
  myResList.Free;
  compileResfile(ResFile);
end;
procedure TStatForm.btnGenClick(Sender: TObject);
begin
  scriptResourceFile2('Bitmap');
end;
function TStatForm.getFileList(aList: TStringList): Integer;
var
  DOSerr: Integer;
  fsrch: TsearchRec;
begin
  Result := 0;
  doserr := FindFirst('*.bmp', faAnyFile, fsrch);
  if (DOSerr = 0) then 
  begin
    while (DOSerr = 0) do 
    begin
      aList.Add(fsrch.Name);
      if (fsrch.attr and faDirectory) = 0 then Inc(Result);
      DOSerr := findnext(fsrch);
    end;
    findClose(fsrch);
  end;
end;
procedure TStatForm.compileResfile(vfile: string);
var 
  i, iCE: Integer;
begin
  {$IFDEF MSWINDOWS}
  iCE := shellapi.shellExecute(0, nil, PChar('BRCC32.exe'),
    PChar(vfile), nil, 0);
  i   := 0;
  repeat
    Inc(i);
    sleep(600);
    Application.ProcessMessages;
  until i >= 10;
  if iCE <= 32 then ShowMessage('compError Nr. ' + IntToStr(iCE));
  {$ENDIF}
end;
printed from
  www.swissdelphicenter.ch
  developers knowledge base