Autor Beitrag
Watsch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: Do 13.04.06 14:59 
Hallo.
Ich habe zwei EXE-Dateien. Die erste ist die Hauptanwendung, mit einer ListBox und zwei Buttons und eine ExtraResManager-Komponente, die zweite Anwendung hat eine Image- und eine ExtraResManager-Komponente. Bei Button1-Klick werden die ausgewählten Bilder (BMP) in die ListBox übertragen. Kein Problem.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
begin
  If OpenDialog1.Execute Then
    begin
    ListBox1.Items.Add(OpenDialog1.FileName);
    end;
end;


Bei Button2-Klick sollen nun die ausgewählten Bilder als neue Resource in der zweiten EXE (hier Test.exe) gespeichert werden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button2Click(Sender: TObject);
var
  i: Integer;
  ResName: TResName;
begin
  ResName := 'BITMAP';

  For i := 1 To ListBox1.Items.Capacity Do
    begin
    ExtraResManager.AddFile(ExtractFileName(ListBox1.Items[i - 1]), i, ResName);
    ExtraResManager.SaveToEXEFile('C:\Test.exe');
    end;
end;


Wenn nur ein Bild in der ListBox ist, klappt es (mittlerweile). Bei mehreren Bildern allerdings bekomme ich die Fehlermeldung: Liste überschreitet das Maximum(1)


Zuletzt bearbeitet von Watsch am Do 13.04.06 16:09, insgesamt 1-mal bearbeitet
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 13.04.06 23:18 
Deine Schleife sollte wohl besser so aussehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  i: Integer;
  ResName: TResName;
begin
  ResName := 'BITMAP';

  for i := 0 To ListBox1.Items.Count - 1 Do
  begin
    ExtraResManager.AddFile(ExtractFileName(ListBox1.Items[i]), i, ResName + IntToStr(i)); // der sowohl ResId als auch ResName müssen eindeutig sein!
    ExtraResManager.SaveToEXEFile('C:\Test.exe');
  end;
end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Watsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: Fr 14.04.06 10:43 
Oh, ich Voll-Strunz! :autsch:
OK, da wäre ich nicht draufgekommen. Allerdings hakt's jetzt beim Zugriff auf die Resourcen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.ImageClick(Sender: TObject);
var
  i: Integer;
begin
  ExtraResManager.LoadFromEXEFile(Application.ExeName);

  For I:=0 To ExtraResManager.Resources.Count - 1 Do
    begin
    ExtraResManager.Resources.Items[I].SaveToFile('C:\Pic' + IntToStr(i) + '.bmp');
    end; 
end;


Damit kann ich die Bilder speichern - klappt auch wunderbar. Aber wie greift man auf die Resourcen zu, ohne sie zu speichern? Mit einem Wort: Wie kann ich die Bilder im Image anzeigen, ohne sie vorher zu speichern?
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 14.04.06 12:59 
Ganz einfach:

ausblenden Delphi-Quelltext
1:
  Image1.Picture.Bitmap.LoadFromStream(ExtraResManager.Resources.Items[<gewünschterIndex>].Stream);					

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Watsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: Fr 14.04.06 13:35 
Hm, soweit war ich zwar auch schon, dennoch wird das Bild nicht angezeigt. Angenommen, die Datei beinhaltet 2 Bilder, dann müsste es ja theoretisch so funktionieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.ImageClick(Sender: TObject);
begin
// Bilder laden, da es sonst die Fehlermeldung "Liste überschreitet das Maximum(1) gibt
  ExtraResManager.LoadFromEXEFile(Application.ExeName);
// Bild ins Image laden und anzeigen
  Image.Picture.Bitmap.LoadFromStream(ExtraResManager.Resources.Items[1].Stream);
end;


Es wird allerdings kein Bild im Image angezeigt.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 14.04.06 13:52 
Ja, müsste schon.. und wenn du das Bild speicherst und ladest wird es korrekt angezeigt?

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Watsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: Fr 14.04.06 14:41 
Ja, dann wird's korrekt angezeigt.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 14.04.06 15:53 
Sollte zwar nicht viel ändern, aber probiers trotzdem mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.ImageClick(Sender: TObject);
var
  bmp: TBitmap;
begin
// Bilder laden, da es sonst die Fehlermeldung "Liste überschreitet das Maximum(1) gibt
  ExtraResManager.LoadFromEXEFile(Application.ExeName);

  bmp := TBitmap.Create;
  bmp.LoadFromStream(ExtraResManager.Resources.Items[1].Stream);
  Iamge1.Picture.Bitmap := bmp;
  bmp.Free;
end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Watsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: Fr 14.04.06 16:41 
Stimmt. Ändert auch nichts...