was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

39 Visitors Online


 
...überprüfen, ob eine Datei Text (ASCII) oder Binäres enthält?
Autor: Marcelo Castro
Homepage: http://www.mcgsoftwares.com
[ Tip ausdrucken ]  

Tip Bewertung (26):  
     


function IsTextFile(const sFile: TFileName): boolean;
//Created By Marcelo Castro - from Brazil

var
 
oIn: TFileStream;
 iRead: Integer;
 iMaxRead: Integer;
 iData: Byte;
 dummy:string;
begin
 
result:=true;
 dummy :='';
 oIn := TFileStream.Create(sFile, fmOpenRead or fmShareDenyNone);
 try
   
iMaxRead := 1000;  //only text the first 1000 bytes
   
if iMaxRead > oIn.Size then
     
iMaxRead := oIn.Size;
   for iRead := 1 to iMaxRead do
   begin
     
oIn.Read(iData, 1);
     if (idata) > 127 then result:=false;
   end;
 finally
   
FreeAndNil(oIn);
 end;
end;

(* ----- Sample call ----- *)

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
OpenDialog1.Execute then
  begin
  if 
IsTextFile(OpenDialog1.FileName) then
  
showmessage('is ascii')
  else showmessage('is BinaryFile')
  end;

end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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