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

21 Visitors Online


 
...patch binary files?
Autor: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
[ Print tip ]  

Tip Rating (7):  
     


// Replaces a string in a file with new string.
// Ersetzt eine Zeichenkette in einer Datei mit einer anderen Zeichenkette.

procedure TForm1.Button1Click(Sender: TObject);
var
  
f: file;
  l: Longint;
  FileName, oldstring, newstring, s: string;
begin
  
oldstring := 'old string';
  newstring := 'new string';
  FileName  := 'c:\YourFileName.xyz';
  
  s := oldstring;
  AssignFile(f, FileName);
  Reset(f, 1);
  for l := 0 to FileSize(f) - Length(oldstring) - 1 do
  begin
    
Application.ProcessMessages;
    Seek(f, l);
    BlockRead(f, oldstring[1], Length(oldstring));
    if oldstring = s then
    begin
      
Seek(f, l);
      BlockWrite(f, newstring[1], Length(newstring));
      ShowMessage('String successfully replaced!');
    end;
    Application.ProcessMessages;
  end;
  CloseFile(f);
end;


 

Rate this tip:

poor
very good


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