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

20 Visitors Online


 
...eine binäre Datei lesen und die Byte Werte als ASCII darstellen?
Autor: P. Below
Homepage: http://www.teamb.com
[ Tip ausdrucken ]  

Tip Bewertung (40):  
     




type
  
TDisplayProc = procedure(const s: stringof object;

procedure ShowBinary(var Data; Count: Cardinal; DispProc: TDisplayProc);

implementation


procedure 
ShowBinary(var Data; Count: Cardinal; DispProc: TDisplayProc);
var
  
line: string[80];
  i: Cardinal;
  p: PChar;
  nStr: string[4];
const
  
posStart = 1;
  binStart = 7;
  ascStart = 57;
  HexChars: PChar = '0123456789ABCDEF';
begin
  
p    := @Data;
  line := '';
  for i := 0 to Count - 1 do
  begin
    if 
(i mod 16) = 0 then
    begin
      if 
Length(line) > 0 then
        
DispProc(line);
      FillChar(line, SizeOf(line), ' ');
      line[0] := Chr(72);
      nStr    := Format('%4.4X', [i]);
      Move(nStr[1], line[posStart], Length(nStr));
      line[posStart + 4] := ':';
    end;
    if p[i] >= ' ' then
      
line[i mod 16 + ascStart] := p[i]
    else
      
line[i mod 16 + ascStart] := '.';
    line[binStart + 3 * (i mod 16)]     := HexChars[(Ord(p[i]) shr 4) and $F];
    line[binStart + 3 * (i mod 16) + 1] := HexChars[Ord(p[i]) and $F];
  end;
  DispProc(line);
end;


procedure TForm1.Display(const S: string);
begin
  
Memo1.Lines.Add(S);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  
ms: TMemoryStream;
begin
  if 
Opendialog1.Execute then
  begin
    
ms := TMemoryStream.Create;
    try
      
ms.LoadFromfile(OpenDialog1.FileName);
      ShowBinary(ms.Memory^, ms.Size, Display);
    finally
      
ms.Free
    end;
  end;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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