home *** CD-ROM | disk | FTP | other *** search
- {Part of Imagelib VCL/DLL Library.
- Written by Jan Dekkers and Kevin Adams (c) 1995. If you are a non
- registered client, you may use or alter this demo only for evaluation
- purposes.
-
- Uses ImageLib 2.2. Changed the callback to a function instead of a
- procedure to let the user cancel out. Added:
-
- scrolling text images
- Cut, Copy and Paste to/from the clipboard
- Printing bitmaps}
-
- unit Ublob;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, DB, DBTables, TDBmulti, StdCtrls, ExtCtrls, DBCtrls,
- Gauges, Mask, Buttons, Clipbrd, Spin, U_p_size, Printers, Ufullscr, UAbout;
-
- type
- TForm1 = class(TForm)
- Table1 : TTable;
- DataSource1 : TDataSource;
- DBNavigator1 : TDBNavigator;
- Gauge1 : TGauge;
- AutodisplayCheckBox : TCheckBox;
- DBEdit1 : TDBEdit;
- StretchCheckBox : TCheckBox;
- BitBtn1: TBitBtn;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- BitBtn2: TBitBtn;
- GroupBox1: TGroupBox;
- RadioButton1: TRadioButton;
- RadioButton2: TRadioButton;
- RadioButton3: TRadioButton;
- CenterCheckBox: TCheckBox;
- BitBtn4: TBitBtn;
- BitBtn5: TBitBtn;
- Timer1: TTimer;
- BitBtn6: TBitBtn;
- Edit1: TEdit;
- BitBtn3: TBitBtn;
- OpenDialog2: TOpenDialog;
- Edit2: TEdit;
- Edit3: TEdit;
- Edit4: TEdit;
- Edit5: TEdit;
- Edit6: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Edit7: TEdit;
- Label7: TLabel;
- Edit8: TEdit;
- GroupBox2: TGroupBox;
- RadioButton4: TRadioButton;
- RadioButton5: TRadioButton;
- BitBtn7: TBitBtn;
- BitBtn8: TBitBtn;
- SaveDialog2: TSaveDialog;
- GroupBox3: TGroupBox;
- SpinEdit1: TSpinEdit;
- SpinEdit2: TSpinEdit;
- Label8: TLabel;
- Label9: TLabel;
- BitBtn9: TBitBtn;
- PrintDialog1: TPrintDialog;
- BitBtn11: TBitBtn;
- BitBtn12: TBitBtn;
- BitBtn13: TBitBtn;
- DBMultiImage1: TDBMultiImage;
- procedure FormCreate(Sender: TObject);
- procedure AutodisplayCheckBoxClick(Sender: TObject);
- procedure StretchCheckBoxClick(Sender: TObject);
- procedure DataSource1DataChange(Sender: TObject; Field: TField);
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- procedure ResolutionClick(Sender: TObject);
- procedure CenterCheckBoxClick(Sender: TObject);
- procedure BitBtn4Click(Sender: TObject);
- procedure BitBtn5Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure BitBtn6Click(Sender: TObject);
- procedure BitBtn3Click(Sender: TObject);
- procedure RadioButton4Click(Sender: TObject);
- procedure BitBtn7Click(Sender: TObject);
- procedure BitBtn8Click(Sender: TObject);
- procedure SpinEdit2Change(Sender: TObject);
- procedure SpinEdit1Change(Sender: TObject);
- procedure BitBtn9Click(Sender: TObject);
- procedure BitBtn11Click(Sender: TObject);
- procedure BitBtn12Click(Sender: TObject);
- procedure BitBtn13Click(Sender: TObject);
- private
- { Private declarations }
- Procedure Trigger(Sender : TObject; Var Done : Boolean);
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {Changed in version 2.2 from a procedure to a function. To cancel return
- a 0 else return a 1}
- Function CallMe(i : integer) : integer; export;
- {Callback function from the dll, EXPORT IS REQUIRED}
- begin
- if Application.Terminated then begin
- {User wants to terminate the program. Pass a 0 to the dll}
- Result:=0;
- end else begin
- {Be nice to others <g>}
- Application.ProcessMessages;
- {process a Gauge}
- Form1.Gauge1.Progress:=i;
- {tell the dll that everything is OK}
- Result:=1;
- end;
- end;
- {---------------------------------------------------------------------}
-
-
- function JustPathname(PathName : string) : string;
- {-Return just the drive:directory portion of a pathname}
- var
- I : Word;
- const
- DosDelimSet : set of Char = ['\', ':', #0];
- begin
- I := Succ(Word(Length(PathName)));
- repeat
- Dec(I);
- until (PathName[I] in DosDelimSet) or (I = 0);
-
- if I = 0 then
- {Had no drive or directory name}
- JustPathname[0] := #0
- else if I = 1 then
- {Either the root directory of default drive or invalid pathname}
- JustPathname := PathName[1]
- else if (PathName[I] = '\') then begin
- if PathName[Pred(I)] = ':' then
- {Root directory of a drive, leave trailing backslash}
- JustPathname := Copy(PathName, 1, I)
- else
- {Subdirectory, remove the trailing backslash}
- JustPathname := Copy(PathName, 1, Pred(I));
- end else
- {Either the default directory of a drive or invalid pathname}
- JustPathname := Copy(PathName, 1, I);
- end;
- {---------------------------------------------------------------------}
-
- {$R *.DFM}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- {Assign a callback function to the VCL/DLL}
- TDBMultiImageCallBack:=CallMe;
- {Is Autodisplay Initial on or off}
- DBMultiImage1.AutoDisPlay:=AutodisplayCheckBox.Checked;
- {If the image data is changed save the blob to a jpeg or Bmp blob}
- DBMultiImage1.UpdateBlobAsJpeg:=RadioButton4.Checked;
-
- {set the values of teh spin edit controls to the values of the vcl}
- SpinEdit2.Value:=DBMultiImage1.JPegSaveSmooth;
- SpinEdit1.Value:=DBMultiImage1.JPegSaveQuality;
-
- If FileExists(ExtractFilePath(Application.ExeName)+'JPSTAMP.DBF') then begin
- {if the table exists open it on creation}
- Table1.DataBaseName:=JustPathName(Application.ExeName);
- Table1.TableName:='JPSTAMP.DBF';
- Table1.Active:=True;
- Table1.Last;
- end;
-
-
- {IMPORTANT
- This is the moving engine for all the messages. Since an applcation
- can have only one OnIdle Trigger, this trigger needs to be subdivided
- by all your moving and animated objects. In this particular case the
- function is called TRIGGER but you can name it as you want as long
- you have a procedure named the same.}
-
- Application.OnIdle:=Trigger;
- end;
- {---------------------------------------------------------------------}
-
- Procedure TForm1.Trigger(Sender : TObject; Var Done : Boolean);
- begin
- {IMPORTANT}
- {This function is called when your app is idle. Subdivide the
- trigger event to your TDBMultiImage objects who may need one.
- If no Message is active it will not take up significant time}
-
- DBMultiImage1.Trigger;
- {DBMultiImage2.Trigger;
- DBMultiImage3.Trigger;}
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.AutodisplayCheckBoxClick(Sender: TObject);
- begin
- {Toggle Autodisplay}
- DBMultiImage1.AutoDisPlay:=AutodisplayCheckBox.Checked;
-
- {Let users know to double click when autodisplay is off}
- DBMultiImage1.ShowHint:= not AutodisplayCheckBox.Checked;
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.StretchCheckBoxClick(Sender: TObject);
- begin
- {Stretch DBImage}
- DBMultiImage1.Stretch:=StretchCheckBox.Checked;
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.CenterCheckBoxClick(Sender: TObject);
- begin
- {Center DBImage}
- DBMultiImage1.Center:=CenterCheckBox.Checked;
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
- begin
- {Reset the Gauge}
- Gauge1.Progress:=0;
-
- {If DBMultiImage1.autodisplay = false then get the blob info
- manually else the vcl will do it automatically}
- If not DBMultiImage1.autodisplay then DBMultiImage1.GetInfoAndType;
-
- {Show the user the blob info}
- Edit1.text:='This blob image is a '+DBMultiImage1.BFiletype;
- Edit2.text:=IntToStr(DBMultiImage1.Bwidth);
- Edit3.text:=IntToStr(DBMultiImage1.BHeight);
- Edit4.text:=IntToStr(DBMultiImage1.Bbitspixel);
- Edit5.text:=IntToStr(DBMultiImage1.Bplanes);
- Edit6.text:=IntToStr(DBMultiImage1.Bnumcolors);
- Edit7.text:=DBMultiImage1.Bcompression;
- Edit8.text:=IntToStr(DBMultiImage1.BSize)+ ' bytes';
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn1Click(Sender: TObject);
- begin
- {load a image file in the current blob}
-
- If OpenDialog1.Execute Then begin
- {Place table in edit mode}
- Table1.Edit;
- {Load the image from file into the blob}
- DBMultiImage1.LoadFromFile(OpenDialog1.FileName);
- {Post the blob}
- Table1.Post;
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn2Click(Sender: TObject);
- var temp : string;
- begin
- {Save the current blob to a jpeg, pcx, gif or Bmp file. The SaveToFile
- will save it as stored in the blob. (no conversion is done here)
- Use SaveToFileAsBMP or SaveToFileAsJpeg to Convert to one another}
-
- {get the extension (filetype) of the stored blob}
- {GetInfoAndType returns the extension of the blob stored}
- if not table1.active then exit;
- temp:=DBMultiImage1.GetInfoAndType;
-
- if temp = 'GIF' then begin
- {set SaveDialog filter to display gif's only}
- SaveDialog1.filter:='GIF files|*.GIF';
-
- {set SaveDialog Default extension}
- SaveDialog1.DefaultExt:='GIF';
- end else
-
- if temp = 'PCX' then begin
- {set SaveDialog filter to display pcx's only}
- SaveDialog1.filter:='PCX files|*.PCX';
-
- {set SaveDialog Default extension}
- SaveDialog1.DefaultExt:='PCX';
- end else
-
- if temp = 'JPG' then begin
- {set SaveDialog filter to display jpeg's only}
- SaveDialog1.filter:='Jpeg files|*.JPG';
-
- {set SaveDialog Default extension}
- SaveDialog1.DefaultExt:='JPG';
- end else
-
- if temp = 'BMP' then begin
- {set SaveDialog filter to display bmp's only}
- SaveDialog1.filter:='BMP files|*.BMP';
- {set SaveDialog Default extension}
- SaveDialog1.DefaultExt:='BMP';
- end;
-
- {save it to file as stored in blob}
- If SaveDialog1.Execute Then
- DBMultiImage1.SaveToFile(SaveDialog1.FileName);
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
-
- procedure TForm1.ResolutionClick(Sender: TObject);
- begin
- {Set resolution and dither the image}
- if RadioButton1.Checked then begin
- {Set resolution to 16 colors}
- DBMultiImage1.JpegResolution:=4;
- {Set dither 1 pass ordered}
- DBMultiImage1.JpegDither:=2;
- end else
-
- if RadioButton2.Checked then begin
- {Set resolution to 256 colors}
- DBMultiImage1.JpegResolution:=8;
- {Set dither 2 pass FS}
- DBMultiImage1.JpegDither:=4;
- end else
-
- if RadioButton3.Checked then begin
- {Set resolution to true color}
- DBMultiImage1.JpegResolution:=24;
- {Set No dither (True color images don't have a palette)}
- DBMultiImage1.JpegDither:=0;
- end;
-
- {Reload the image }
- Table1.Refresh;
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
-
- procedure TForm1.BitBtn4Click(Sender: TObject);
- begin
- {Check to see if image is there}
- if DBMultiImage1.Picture.Bitmap <> nil then
- {Copy the image to the clipboard}
- DBMultiImage1.CopyToClipboard;
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn5Click(Sender: TObject);
- {Paste image from clipboard}
- begin
- {does the clipboard has the right format?}
- if Clipboard.HasFormat(CF_PICTURE) then
- {Yep it does. Paste image from clipboard}
- DBMultiImage1.PastefromClipboard;
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- {En/Disable Paste Button if clipboard has format}
- BitBtn5.Enabled:=Clipboard.HasFormat(CF_PICTURE);
- {Enable/disable certain buttons}
- {Button is only then enabled if table is active}
- BitBtn1.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn2.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn4.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn6.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn7.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn8.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn9.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn11.Enabled:=Table1.Active;
- {Button is only then enabled if table is active}
- BitBtn13.Enabled:=Table1.Active;
- {Box is only then visible if table is active and blob is a jpeg }
- GroupBox1.Visible:=Table1.Active and (DBMultiImage1.BFiletype = 'JPEG');
- {Box is only then visible if table is active and field is in edit state}
- GroupBox2.Visible:=Table1.Active and (DataSource1.State in [dsEdit, dsInsert]);
- {Box is only then visible if table is active and field is in edit state and update is in jpeg mode}
- GroupBox3.Visible:=Table1.Active and RadioButton4.Checked and (DataSource1.State in [dsEdit, dsInsert]);
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn6Click(Sender: TObject);
- begin
- {Append a record and store an image file into the blob}
- If OpenDialog1.Execute Then begin
- {Place table in edit mode}
- Table1.Append;
- {Load the image from file into the blob}
- DBMultiImage1.LoadFromFile(OpenDialog1.FileName);
- {Post the blob}
- Table1.Post;
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn3Click(Sender: TObject);
- begin
- {open the table}
- If OpenDialog2.execute then begin
- Table1.Active:=False;
- Table1.DataBaseName:=JustPathname(OpenDialog2.FileName);
- Table1.TableName:=OpenDialog2.FileName;
- Table1.Active:=True;
- end;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.RadioButton4Click(Sender: TObject);
- begin
- {If the image data is changed save the blob to a jpeg or Bmp blob}
- DBMultiImage1.UpdateBlobAsJpeg:=RadioButton4.Checked;
-
- {Hide or show the jpeg update/save options}
- GroupBox3.Visible:=RadioButton4.Checked;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn7Click(Sender: TObject);
- {save or convert the blob to a BMP file}
- {make sure that the blob is displayed before saving to file}
- begin
- {set SaveDialog filter to display bmp's only}
- SaveDialog2.filter:='BMP files|*.BMP';
-
- {set SaveDialog Default extension}
- SaveDialog2.DefaultExt:='BMP';
-
- if SaveDialog2.Execute then
- {Save it}
- DBMultiImage1.SaveToFileAsBMP(SaveDialog2.Filename);
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn8Click(Sender: TObject);
- {save or convert the blob to a Jpeg file}
- {make sure that the blob is displayed before saving to file}
- begin
- {set SaveDialog filter to display jpeg's only}
- SaveDialog2.filter:='Jpeg files|*.JPG';
-
- {set SaveDialog Default extension}
- SaveDialog2.DefaultExt:='JPG';
-
- if SaveDialog2.Execute then
- {Save it}
- DBMultiImage1.SaveToFileAsJpeg(SaveDialog2.Filename);
-
- {reset the gauge to 0}
- Gauge1.Progress:=0;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.SpinEdit2Change(Sender: TObject);
- begin
- {Set the smooth of the jpeg to save or upate a blob}
- DBMultiImage1.JPegSaveSmooth:=SpinEdit2.Value;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.SpinEdit1Change(Sender: TObject);
- begin
- {Set the quality of the jpeg to save or upate a blob}
- DBMultiImage1.JPegSaveQuality:=SpinEdit1.Value;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn9Click(Sender: TObject);
- begin
- if PrintDialog1.execute then begin
- {Initialize the height spinedit of the printsize dialog box}
- Printersize.HeigthSpinEdit.Value:=DBMultiImage1.Picture.Height;
- {Initialize the width spinedit of the printsize dialog box}
- Printersize.WidthSpinEdit.Value:=DBMultiImage1.Picture.Width;
- {Show it}
- Printersize.ShowModal;
- if Printersize.Modalresult = mrok then
-
- {print TMultiImage}
- DBMultiImage1.PrintMultiImage(0,0,Printersize.WidthSpinEdit.Value,Printersize.HeigthSpinEdit.Value);
-
- {Hide it if done}
- Printersize.hide;
- end;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn11Click(Sender: TObject);
- begin
- {copy DB Blob image to fullscreen image}
- FullSlide.MultiImage1.Picture.Graphic:=DBMultiImage1.Picture.Graphic;
- {show the image fulscreen}
- FullSlide.showmodal;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn12Click(Sender: TObject);
- {about box}
- begin
- {Copy the image to the image of he about box}
- AboutBox.Image1.Picture.Graphic:=DBMultiImage1.Picture.Graphic;
- {show the about box}
- AboutBox.showmodal;
- end;
- {---------------------------------------------------------------------}
-
- procedure TForm1.BitBtn13Click(Sender: TObject);
- begin
- {Place the Database in append mode}
- Table1.Append;
- {Create a New Message}
- If DBMultiImage1.CreateMessage then
- {Post or cancel that thing}
- Table1.Post
- else
- Table1.Cancel;
- end;
-
- {---------------------------------------------------------------------}
- {Scrolling messages are a new Blob Format.
- Undocumented in this release. For examples how to
- use look at the project BLOBMM which can be
- found in BlobDemo.Zip}
- {---------------------------------------------------------------------}
- end.
-