お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"バイナリファイルをコンソールにダンプ"



みなさんこんにちは。

ダンプというと聞こえはいいですが、単にバイナリファイルをコンソールに
垂れ流すだけのプログラムです。(^^ゞ
ま、、、のサンプルというこ
とで。。(^^;

                                 Yukimi Sake GHE01746@nifty.ne.jp

//Form にOpenDialog と Button を1個ずつ貼り付けてください。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs,StdCtrls;

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;
  F:TFileStream;
  Buff:Array[0..15] of Byte;
const counter=16;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
  var
    i,j,m:integer;
    s:string;
begin
  if OpenDialog1.Execute then
  begin
    AllocConsole;
    try
      F:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
      for i:=0 to (F.Size div counter)-1 do begin
        F.ReadBuffer(Buff,counter);
        for j:=0 to counter-1 do begin
          s:=s+IntTohex(Buff[j],2)+' ';
        end;
        writeln(s);
        s:='';
      end;
      m:=F.Size mod counter;
      if m >0 then begin
        F.ReadBuffer(Buff,m);
        for j:=0 to m-1 do begin
          s:=s+IntTohex(Buff[j],2)+' ';
        end;
        writeln(s);
        s:='';
      end;
    finally
      F.Free;
    end;
  end;
end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FreeConsole;
end;

end.
 


- FDELPHI  MES(16):玉石混淆みんなで作るSample蔵【見本蓄積】 00/11/22 -

Original document by 雪見酒          氏 ID:(GHE01746)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum