Autor Beitrag
Jukka
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Mi 25.10.06 14:22 
Hallo,

Ich habe ein problem bei einer Funktion. Ich habe ein eigenes dateiformat geschrieben die Daten via MemoryStream in einer große Speichert. Nun möchste ich diese auslesen.

Ich habe 3 Units. Einen LoadingScreen, dann das Mainform und die Lib für das eigenedateiformat.

der code der LodingUnit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TLoadingScreen.ApplicationEvents1Activate(Sender: TObject);
begin
LoadIRF(main.Form1.CardPic,extractfilepath(Application.ExeName)+'\rfd\cards.irf',ProgressBar1);
LoadIRF(main.Form1.TexturePic,extractfilepath(Application.ExeName)+'\rfd\textures.irf',ProgressBar1);
LoadingScreen.Hide;
Form1.Show;
end;
Das laden funktioniert einwandfrei ohne fehler

die lib mit typ und auschnit beim laden des streams:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
  TPicData = packed record
    Name: String;
    DataSize: Int64;
    Data: TMemoryStream;
  end;

  TPic = packed Array of TPicData;

  { ... }
  procedure LoadIRF(PicArray: TPic; Filename: string; ProgressBar: TProgressBar);
  { ... }
//for schleife vorher header ausgelesen etc
      Stream.Read(PicArray[i].DataSize, SizeOf(PicArray[i].DataSize));
      PicArray[i].Data := TMemoryStream.Create;
      PicArray[i].Data.CopyFrom(Stream, PicArray[i].DataSize);
    end;

Wenn ich hier PicArray[i].Data.SaveToFile('test.gif'); eingebe geht es einwandfrei

Jeoch so nichtmehr
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
type
  TForm1 = class(TForm)
  public
    CardPic,TexturePic: TPic;

{ ... }

procedure TForm1.NewClick(Sender: TObject);
var
  test: TGIFImage;
begin
test := TGIFImage.Create;
Form1.CardPic[12].Data.Position := 0;
test.LoadFromStream(Form1.CardPic[12].Data);
test.Transparent := TRUE;
Form1.Image.Picture.Graphic := test;
test.Free;
end;


Dies erzeugt einen zugriffsfehler bei LoadFromStream


Alle uses sind gesetzt usw aber es geht einfach nicht in form 1 nur un der lib geht es, warum? kann mir wer helfen?

Danke im vorraus. Jukka
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 14:54 
Moin!

Ist etwas undurchsichtig, dein Problem... :? Ich blicke auch nicht so richtig durch, aber zwei Sachen fallen mir auf:

a) TPic = packed Array of TPicData; ist doch eine programminterne Struktur, die du nicht auf die Platte schreibst, dann würde ich das packed weglassen (ist aber nur eine Optimierung, hat wohl nix mit dem Fehler zu tun; aber trotzdem ;))

b) CardPic und TexturePic sind public-Eigenschaften der Main-Form-Klasse; zur Laufzeit deines Loadscreen-Forms ist das möglicherweise aber noch gar nicht initialisiert (das Formularobjekt muss ja auch schon angelegt sein!). Deshalb würde ich diese Arrays in der Loadingscreen-Klasse ansiedeln.

Wenn du damit nicht weiter kommst, dann zeig mal mehr Code. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Mi 25.10.06 15:18 
Auch wenn ich es in die loadingunit lege geht dies nicht

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var
  LoadingScreen: TLoadingScreen;
  CardPic,TexturePic: TPic;

implementation


{$R *.dfm}
{==============================================================================}
procedure TLoadingScreen.ApplicationEvents1Activate(Sender: TObject);
begin
LoadIRF(CardPic,extractfilepath(Application.ExeName)+'\rfd\cards.irf',ProgressBar1);
LoadIRF(TexturePic,extractfilepath(Application.ExeName)+'\rfd\textures.irf',ProgressBar1);
LoadingScreen.Hide;
Form1.Show;
end;


main:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.NewClick(Sender: TObject);
var
  test: TGIFImage;
begin
test := TGIFImage.Create;
loadingunit.CardPic[12].Data.Position := 0;
test.LoadFromStream(loadingunit.CardPic[12].Data);
test.Transparent := TRUE;
Form1.Image.Picture.Graphic := test;
test.Free;
end;


Lib:
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:
procedure LoadIRF(PicArray: TPic; Filename: string; ProgressBar: TProgressBar);
var
  PicFileHeader: TPicFile;
  FileStream: TFileStream;
  Stream: TMemoryStream;
  I: integer;
  Len: Int64;
begin
  FileStream := TFileStream.Create(Filename, fmOpenRead);
  Stream := TMemoryStream.Create;
  DeCompressStream(FileStream, Stream);
  FileStream.Free;
  try
    Stream.Read(PicFileHeader.Version, SizeOf(PicFileHeader.Version));
    Stream.Read(PicFileHeader.ImagesCount, SizeOf(PicFileHeader.ImagesCount));
    SetLength(PicArray, PicFileHeader.ImagesCount);
    ProgressBar.Max := ProgressBar.Max + PicFileHeader.ImagesCount;
    for i:= 0 to Length(PicArray) - 1 do begin
      ProgressBar.Position := ProgressBar.Position + 1;
      Application.ProcessMessages;
      Stream.Read(Len, SizeOf(Len));
      SetLength(PicArray[I].Name, Len);
      Stream.Read(PChar(PicArray[i].name)^, Len);
      Stream.Read(PicArray[i].DataSize, SizeOf(PicArray[i].DataSize));
      PicArray[i].Data := TMemoryStream.Create;
      PicArray[i].Data.CopyFrom(Stream, PicArray[i].DataSize);
    end;
  finally
    Stream.free;
  end;
end;

(typen siehe post vorher)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 16:27 
Moin!

Zeigste nochmal die Projektdatei? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Mi 25.10.06 16:33 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
program Editor;

uses
  Forms,
  main in 'src\main.pas' {Form1},
  IRF in 'src\IRF.pas',
  loadingunit in 'src\loadingunit.pas' {LoadingScreen},
  GIFImageLib in 'src\GIFImageLib.pas',
  DBS in 'src\DBS.pas';

{$R res\Editor.res}

begin
    Application.Initialize;
    Application.CreateForm(TLoadingScreen, LoadingScreen);
    Application.CreateForm(TForm1, Form1);  // absicht
    Form1.Hide;
    Application.Run;
end.


irgendwas falsch?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 19:20 
Moin!

Hmm... :? wenn man mal davon absieht, dass das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var  
  test: TGIFImage;  
begin  
test := TGIFImage.Create;  
loadingunit.CardPic[12].Data.Position := 0;  
test.LoadFromStream(loadingunit.CardPic[12].Data);  
test.Transparent := TRUE;  
Form1.Image.Picture.Graphic := test;  
test.Free;

eigentlich nur gegen die Wand laufen kann (du solltest da besser mit .Assign() arbeiten), du aber sagst, dass du den MemoryStream aus dem record korrekt in eine Datei schreiben kannst, tja... :gruebel: dann kann ich da auf Anhieb keinen Fehler sehen. :|

Kann dir nur anbieten, dein Projekt als ZIP (ohne die EXE) in den Anhang zu stellen, dann versuche ich das mal nachzustellen.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Mi 25.10.06 21:16 
Das mit dem Graphic := test geht da TGIFImage eine ableitung von TGraphic ist. Ich hab es jetzt so gemacht und die Streams alle in der IRF unit gespeichert und von der main dann auf die IRF zugegriffen zwar ein wenig mehr schreibarbeit aber es geht

Trodzdem danke

Jukka
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 25.10.06 21:19 
Moin!

user profile iconJukka hat folgendes geschrieben:
Ich hab es jetzt so gemacht und die Streams alle in der IRF unit gespeichert und von der main dann auf die IRF zugegriffen zwar ein wenig mehr schreibarbeit aber es geht

Fein. ;)

user profile iconJukka hat folgendes geschrieben:
Das mit dem Graphic := test geht da TGIFImage eine ableitung von TGraphic ist.

Ich habe nicht bestritten, dass die Zuweisung geht, aber du darfst doch nicht direkt danach das (selbe!) Objekt freigeben... :gruebel: ;)

cu
Narses

//EDIT: Ach ja, wenn dein Problem gelöst ist, markierst du dann den Thread noch entsprechend? Danke. ;)

_________________
There are 10 types of people - those who understand binary and those who don´t.