whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

33 Visitors Online


 
...Build Resources from files located in a Directory?
Autor: Max Kleiner
Homepage: http://max.kleiner.com
[ Print tip ]  

Tip Rating (7):  
     


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


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners