Autor Beitrag
Moritz M.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1672



BeitragVerfasst: Mo 12.04.04 23:46 
Hallo :D

Folgendes Problem: Ich will gerne einen kleinen Hexeditor (Ich weiß, gibt's massenweise - Trotzdem! ) in Delphi schreiben, und da würde mich interessieren wie ich eine Datei eines beliebigen Types (Gibt es verschiedene Typen? ) einlesen kann. (Sagen wir einfach mal in ein Array)
Könnt ihr mir helfen?

Schönen Gruß
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Di 13.04.04 12:45 
Hi Onz

eine kleine Demo. Zwar nicht in einem Array, sondern in einem StringGrid. Ich will schließlich was sehen! :D
ICh habe es auf die Ersten 10 HexZeilen begrenzt, sollte aber auch über die ganze Länge des Streams laufen.

ausblenden volle Höhe Delphi-Quelltext
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:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
unit UnitMain;

interface

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

type
  TForm1 = class(TForm)
    BuOpen: TButton;
    OpenDLG: TOpenDialog;
    SGHexdata: TStringGrid;
    SGCharData: TStringGrid;
    procedure BuOpenClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
  SGHexdata.ColCount := 17;
  SGHexdata.RowCount := 11;
  for i:=1 to 16 do
    SGHexdata.ColWidths[i]:= 20;
  for i:=0 to 10 do
    SGHexdata.RowHeights[i]:= 20;
  SGCharData.ColCount := 16;
  SGCharData.RowCount := 11;
  for i:=0 to 15 do
    SGCharData.ColWidths[i]:= 20;
  for i:=0 to 10 do
    SGCharData.RowHeights[i]:= 20;
end;

procedure TForm1.BuOpenClick(Sender: TObject);
var FStream : TFileStream;
    LC,HXC:integer;
    LStr:string;
    ByteBuff:byte;
begin
  if OpenDLG.Execute then begin
    FStream:=TFileStream.Create(OpenDLG.FileName,fmOpenRead);
    try
      FStream.Seek(0,soFromBeginning);
      for LC:=0 to 10 do begin
        LStr:='';
        for HXC :=1 to 16 do begin
          FStream.ReadBuffer(ByteBuff,1);
          SGHexdata.Cells[HXC,LC+1] := IntToHex(ByteBuff,2);
          SGCharData.Cells[HXC-1,LC+1]:= Chr(ByteBuff);
        end;
      end;
    finally
      FStream.Free;
    end;
  end;
end;

end.
Moritz M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1672



BeitragVerfasst: Di 13.04.04 13:05 
Danke, ich schau's mir heute Abend mal an!
Simon Joker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236
Erhaltene Danke: 1



BeitragVerfasst: Di 13.04.04 13:18 
PS: den LStr kannst du entsorgen, der ist nur vom schnellen probieren übrig geblieben.