www.pudn.com > Desktop-Manager.rar > Unit7.pas, change:2004-07-30,size:2805b


unit Unit7; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, JPEG; 
 
type 
  TForm7 = class(TForm) 
    Label1: TLabel; 
    Edit1: TEdit; 
    Button1: TButton; 
    Button2: TButton; 
    procedure Button2Click(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Form7: TForm7; 
 
implementation 
uses unit1; 
{$R *.dfm} 
 
procedure TForm7.Button2Click(Sender: TObject); 
begin 
  close; 
end; 
 
procedure TForm7.Button1Click(Sender: TObject); 
var 
  i:integer; 
  JPEG:TJPEGImage; 
begin 
  //将程序目录下的picture.dmf文件拷贝一个副本,以Eidt1.text为名字 
  CopyFile(pchar('pictures.dmf'),Pchar(Edit1.Text+'.dmf'),true); 
  //关闭当前连接,将连接指向新的数据库文件 
  Form1.ADOConnection1.Close; 
  Form1.ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=' 
              +GetCurrentDir()+'/'+Edit1.Text+'.dmf;Persist Security Info=False'; 
  Form1.ADOConnection1.Open();//打开新连接 
  Form1.ADOQuery1.Active:=true; 
  //设置主对话框标题 
  Form1.Caption:='桌面背景图片管理器    [ '+GetCurrentDir+Edit1.Text+'.dmf ]'; 
  //清空副本中的所有数据,成为新建的数据库文件 
  for i:=1 to Form1.ADOQuery1.RecordCount do 
  begin 
    Form1.ADOQuery1.Delete; 
  end; 
//////////////////////////////////////////////////////////////// 
///以下代码和form1的初始化代码大部分一样 
  if Form1.DataSource1.DataSet.FieldByName('picture').IsNull=false then 
  begin 
    JPEG:=TJPEGImage.Create;//JEPG对象做为中间变量 
    try//JPEG从数据库中读出图片后付给Image1 
      JPEG.Assign(Form1.DataSource1.DataSet.FieldByName('picture')); 
      Form1.Image1.Picture.Assign(JPEG); 
      NumPictures:=Form1.ADOQuery1.RecordCount;//得到数据库中的记录条数 
    finally 
      JPEG.Free;// 释放JPGE对象 
    end; 
   // Form1.SpeedButton1.Enabled:=false;//由于初始时指向第一条记录,所以根据 
   // Form1.SpeedButton2.Enabled:=true; //情况设置按钮的可用情况 
  end 
  else 
  begin 
    Form1.Image1.Picture.Assign(nil); 
   // Form1.SpeedButton1.Enabled:=false;//若数据库为空 
   // Form1.SpeedButton2.Enabled:=false;//分别设置相关按钮为不可用 
   // Form1.SpeedButton3.Enabled:=false; 
   // Form1.SpeedButton4.Enabled:=false; 
    Form1.DeleteFormDB.Enabled:=false; 
    Form1.SaveToFile.Enabled:=false; 
    Form1.SetToDesktop.Enabled:=false; 
    Form1.rename.Enabled:=False; 
    Form1.ShowAll.Enabled:=False; 
    Form1.FiltByName.Enabled:=False; 
    Form1.CopyToCBoard.Enabled:=False; 
    Form1.CutToCBoard.Enabled:=False; 
    NumPictures:=0;//同时将指示数据库记录条数的变量置为0 
  end; 
  Form1.Label3.Caption:=IntTostr(NumPictures)+'   张';//显示数据库记录条数 
  close; 
end; 
 
end.