Einzelnen Beitrag anzeigen

calikey

Registriert seit: 19. Mär 2015
29 Beiträge
 
Delphi XE7 Architect
 
#5

AW: PDF's und Jpg im Datensatz speichern, vorschau und abrufen

  Alt 31. Mär 2015, 12:35
So hab bissel was gefunden und versucht es um zuschreiben aber delphi mag nicht. jetzt ist eure hilfe gefragt
Delphi-Quellcode:
unit doku;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.ImgList,
  Vcl.ExtDlgs, Data.DB, Datasnap.DBClient, Vcl.DBCtrls, Vcl.StdCtrls,
  gtScrollingPanel, gtPDFViewer, gtPDFClasses, gtCstPDFDoc, gtExPDFDoc,
  gtExProPDFDoc, gtPDFDoc, gtPDFPrinter, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB;

type
  TForm2 = class(TForm)
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    SaveDialog1: TSaveDialog;
    gtPDFViewer1: TgtPDFViewer;
    gtPDFViewer2: TgtPDFViewer;
    gtPDFViewer3: TgtPDFViewer;
    dbDemos: TClientDataSet; //von mir geändert
    tVenues: TClientDataSet; //von mir geändert
    tVenuesVenueNo: TAutoIncField;
    tVenuesVenue: TStringField;
    tVenuesCapacity: TIntegerField;
    tVenuesVenue_Map: TGraphicField;
    tVenuesRemarks: TMemoField;
    DataSource1: TDataSource;
    DBNavigator1: TDBNavigator;
    DBMemo1: TDBMemo;
    DBImage1: TDBImage;
    btLoadMemo: TButton;
    btSaveMemo: TButton;
    btLoadImage: TButton;
    btSaveImage: TButton;
    odBlob: TOpenDialog;
    sdBlob: TSaveDialog;
    ClientDataSet1: TClientDataSet;
    ClientDataSet1Arbeitsvertragimg: TBlobField;
    ClientDataSet1kopie1: TBlobField;
    ClientDataSet1kopie2: TBlobField;
    ClientDataSet1kopie3: TBlobField;
    ClientDataSet1kopie4: TBlobField;
    ClientDataSet1kopie5: TBlobField;
    ClientDataSet1kopie6: TBlobField;
    ClientDataSet1kopie7: TBlobField;
    ClientDataSet1kopie8: TBlobField;
    ClientDataSet1kopie9: TBlobField;
const
  TClientDataSet: String = '..\..\Data\Demos.abs';
    procedure FormCreate(Sender: TObject);
    procedure btLoadMemoClick(Sender: TObject);
    procedure btSaveMemoClick(Sender: TObject);
    procedure btLoadImageClick(Sender: TObject);
    procedure btSaveImageClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var

  Form2: TForm2;
  openDialog : TOpenDialog;

implementation

{$R *.dfm}

uses Unit1;

procedure TForm2.FormCreate(Sender: TObject);
begin
  dbDemos.DatabaseFileName := ExtractFilePath(Application.ExeName) + DataBaseFileName; //Hier Tclientdataset enthält kein databasefilename
  dbDemos.Open;
  tVenues.Open;
end;

procedure TForm2.btLoadMemoClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
 if (odBlob.Execute) then
   begin
     tVenues.Edit;
     try
       BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('kopie1'),bmWrite);
       FileStream := TFileStream.Create(odBlob.FileName,fmOpenRead or fmShareDenyNone);
       BlobStream.CopyFrom(FileStream,FileStream.Size);
       FileStream.Free;
       BlobStream.Free;
       tVenues.Post;
     except
       tVenues.Cancel;
     end;
   end;
end;

procedure TForm2.btSaveMemoClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
  if (sdBlob.Execute) then
    begin
      FileStream := TFileStream.Create(sdBlob.FileName,fmCreate);
      BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('kopie1'),bmRead);
      FileStream.CopyFrom(BlobStream,BlobStream.Size);
      BlobStream.Free;
      FileStream.Free;
    end;
end;

procedure TForm2.btLoadImageClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
 if (odBlob.Execute) then
   begin
     tVenues.Edit;
     try
       BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('kopie1'),bmWrite);
       FileStream := TFileStream.Create(odBlob.FileName,fmOpenRead or fmShareDenyNone);
       BlobStream.CopyFrom(FileStream,FileStream.Size);
       FileStream.Free;
       BlobStream.Free;
       tVenues.Post;
     except
       tVenues.Cancel;
       raise;
     end;
   end;
end;

procedure TForm2.btSaveImageClick(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
  if (sdBlob.Execute) then
    begin
      FileStream := TFileStream.Create(sdBlob.FileName,fmCreate);
      BlobStream := tVenues.CreateBlobStream(tVenues.FieldByName('kopie1'),bmRead);
      FileStream.CopyFrom(BlobStream,BlobStream.Size);
      BlobStream.Free;
      FileStream.Free;
    end;
end;

end.
was ist mein fehler oder besser wie muss ich das ändern?
  Mit Zitat antworten Zitat