Mega Code Archive

 
Categories / Delphi / Files
 

How to Build Resources from files located in a Directory

Title: How to Build Resources from files located in a Directory 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;