1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| const NoSrc = -1; // Fichier source n'existe pas
ExDst = -2; // Fichier destin existe déjà
function BinToHexa (nSrc, nDst : string): integer;
var Buff: array[0..15] of byte;
i, nbLu: integer;
var fSrc: file;
fDst: text;
begin
result := 0;
if not FileExists(nSrc) then
result := NoSrc
else if not FileExists(nSrc) then
result := ExDst
else begin
assignfile (fSrc, nSrc);
reset (fSrc, 1);
assignfile (fDst, nDst);
rewrite (fDst);
while not eof(fSrc) do
begin
blockread( fSrc, Buff, 16, nbLu);
for i := 0 to nbLu-1 do
write (fDst, format('%2.2x ', [Buff[i]]));
// ou en décimal write (fDst, format('%3.3d ', [Buff[i]]));
inc(result, NbLu);
writeln(fDst);
end;
closefile (fSrc);
closefile (fDst)
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var nSrc, nDst:string;
Nbr : integer;
begin
if opendialog1.execute then
begin
nSrc := opendialog1.filename;
nDst := copy(nSrc, 1, pos(extractfileext(nSrc), nSrc)-1) + '.txt';
Nbr := BinToHexa( nSrc, nDst);
Memo1.lines.loadfromfile(nDst);
end;
end; |
Partager