Announcement

Collapse
No announcement yet.

Klasse erzeugen_access Violation ...WARUM??

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Klasse erzeugen_access Violation ...WARUM??

    was habe ich wieder falsch gemacht! Ich bekomme ständig ein Access Violation Fehler!!
    <br>
    <pre>
    unit PCIDSK;

    interface

    uses Sysutils,classes;

    type TPix = class(TObject)
    id:array[0..63] of char;
    function getid:string;
    constructor createPix(pix:string) ;
    end;
    implementation

    constructor TPix.createPix(pix:string);
    var
    pixfile:TStream;
    begin
    inherited Create;
    pixfile:=Tfilestream.Create(pix,fmOpenRead);
    pixfile.Position:=49;
    pixfile.Read(id,sizeof(id));
    pixfile.free;
    end;

    function TPix.getid:string;
    begin
    result:=id;
    end;

    end.

    </pre>

  • #2
    Bei mir gehts:<BR>
    <BR>
    <PRE>
    unit unTest;

    interface

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

    type
    TPix = class(TObject)
    id: array[0..63] of char;
    function GetId: string;
    constructor CreatePix(Pix: String);
    end;

    TForm1 = class(TForm)
    AStdBtn1: TAStdBtn;
    procedure AStdBtn1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    private
    objPix: TPix;
    public
    { Public-Deklarationen }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.DFM}

    { TPix }

    constructor TPix.CreatePix(Pix: String);
    var
    PixFile: TStream;
    begin
    inherited Create;
    Pixfile := TFileStream.Create(Pix, fmOpenRead);
    Pixfile.Position := 49;
    Pixfile.Read(Id, SizeOf(Id));
    Pixfile.Free;
    end;

    function TPix.GetId: string;
    begin
    Result := Id;
    end;

    procedure TForm1.AStdBtn1Click(Sender: TObject);
    begin
    objPix.CreatePix('unTest.pas');
    AStdBtn1.Caption := objPix.GetId;
    end;

    procedure TForm1.FormActivate(Sender: TObject);
    begin
    objPix := TPix.Create;
    end;

    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    objPix.Free;
    end;

    end.
    </PRE&gt

    Comment

    Working...
    X