Thema: Delphi Datei aus .res kopieren

Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2
  Alt 23. Mai 2003, 21:28
Delphi-Quellcode:
procedure TForm1.LoadMaps(ID: Integer; MemoText, StatbarText: String);
var
  i : Integer;
  MapStream: TResourceStream;
  jpg : TJPEGImage;
begin
  Memo1.Text := MemoText;
  Statusbar1.Panels[0].Text := StatbarText;
  for i := 0 to 2 do
  begin
    MapStream := TResourceStream.Create(hInstance, 'MAP'+IntToStr(ID+i), 'JPEG');
    with TImage(FindComponent('Image'+IntToStr(i+1))) do
    begin
      try
        jpg := TJPEGImage.Create;
        try
          jpg.LoadFromStream(MapStream);
          Picture.Graphic := jpg;
        finally
          jpg.Free;
        end;
      finally
        MapStream.Free;
      end;
    end;
  end;
end;
Mußt du dir noch etwas zurecht basteln. Oder die nonVCL-Version?
Delphi-Quellcode:
{ following code is copied directly from Assarbad }
function putbinresto(binresname: string; path: string): boolean;
var ResSize, HG, HI, SizeWritten, hFileWrite: Cardinal;
begin
  result := false;
  //find resource
  HI := FindResource(hInstance, @binresname[1], 'BINRES');
  //if legal handle, go on
  if HI <> 0 then
  begin
    //load resource and check the handle
    HG := LoadResource(hInstance, HI);
    if HG <> 0 then
    begin
      //check resource size (needed to copy a block of data)
      ResSize := SizeOfResource(hInstance, HI);
      //create the file
      hFileWrite := CreateFile(@path[1], GENERIC_READ or GENERIC_WRITE,
        FILE_SHARE_READ or FILE_SHARE_WRITE, nil, CREATE_ALWAYS,
        FILE_ATTRIBUTE_ARCHIVE, 0);
      //if succeeded ...
      if hFileWrite <> INVALID_HANDLE_VALUE then
      try
        //write to it
        result := (WriteFile(hFileWrite, LockResource(HG)^, ResSize,
          SizeWritten, nil) and (SizeWritten = ResSize));
      finally
        //close file
        CloseHandle(hFileWrite);
      end;
    end;
  end;
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat