⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 工作之余做的一些实例,希望对大家有用,共同学习,相互促进
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, DBCtrls, ExtDlgs, StdCtrls, ExtCtrls, Mask, Menus,
  WinSkinData, ImgList;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    table1: TADOTable;
    DataSource1: TDataSource;
    DBImage1: TDBImage;
    Button1: TButton;
    OpenPictureDialog1: TOpenPictureDialog;
    DBNavigator1: TDBNavigator;
    txtPATH: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    txtNAME1: TEdit;
    txtNAME: TDBEdit;
    Label3: TLabel;
    labTPZS: TLabel;
    PopupMenu1: TPopupMenu;
    tpcz: TMenuItem;
    tpgm: TMenuItem;
    N1: TMenuItem;
    bbll: TMenuItem;
    SkinData1: TSkinData;
    ImageList1: TImageList;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure TPZS(Sender: TObject);
    procedure tpczClick(Sender: TObject);
    procedure tpgmClick(Sender: TObject);
    procedure bbllClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);//显示图片总数
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  strpathname,strpath:string;//定义一个存入图片路径的变量
implementation

uses TPCZUnit2, TPGMUnit2, BBLLUnit2;

{$R *.dfm}
//-----------------------------------------------------------------------------------------
//在一个路径中截取最后一个"\"后的所有字符
function Gshow_title(route{路径},sign{符号"\"}:string;mark{case 的标号}:integer):string;
var
i,k:integer;
begin  
  route:=trim(route);
  sign:=trim(sign);
  case mark of
    1:begin
    k:=0;
    for i:=1 to length(route) do
      begin
        if route[i]=trim(sign) then
          begin
            k:=i+1;
          end;
      end;//结束for循环
     strpathname:=copy(route,k,length(route));//把route里的最后一个"\"后面的内容拷贝到route中,后赋给strpathname,就可以得到图片的名称了
    end;
  end;
end;
//-----------------------------------------------------------------------------------------

procedure TForm1.Button1Click(Sender: TObject);//打开且保存BMP图像按钮
begin
if OpenPictureDialog1.Execute then
  begin
    //--------------------------------------------------------------------------------------
    txtname1.Visible:=true;//可见
    txtname1.Enabled:=false;//不可用
    txtname.Visible:=false;//不可用,不可见
    //--------------------------------------------------------------------------------------
    strpath:=OpenPictureDialog1.FileName;//打开图片对话框中的图片的路径赋给strpath
    txtPATH.Text:=strpath;//把strpath里的内容赋给txtPATH
    strpathname:=txtPATH.Text;//把txtPATH里的内容赋给strpathname
    Gshow_title(strpathname,'\',1);//调用"function Gshow_title(route{路径},sign{符号"\"}:string;mark{case 的标号}:integer):string;"函数
    txtNAME.Text:=strpathname;//显示图片的名称{把DBEdit的DataField关联到数据表存放"图片名称"的那个字段}
    txtNAME1.Text:=strpathname;//向数据库里添加图片的名称
    table1.Insert;
    table1.FieldByName('name').AsString:=strpathname;
    //--------------------------------------------------------------------------------------
    //说明
    {把DBImage的DataField关联到数据表存放"图片"的那个字段}
    tblobfield(table1.FieldByName(dbimage1.DataField)).LoadFromFile(OpenPictureDialog1.FileName);//把打开的图片添加到数据库中
    table1.Post;
    application.MessageBox('此图片'+#13+'已经存入数据库中!','SUER开发小组',mb_ok+mb_iconinformation);
    TPZS(Sender);//调用显示图片总数函数
  end;
dbimage1.LoadPicture;//显示图片
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  //初始化
  if (table1.RecordCount<1) then
    begin
      txtname1.Visible:=true;//如果数据表中的记录为"0",那么"txtname1"为可见,否则为不可见
      txtname.Visible:=false;//如果数据表中的记录为"0",那么"txtname1"为不可见,否则为可见
    end
  else
    begin
      txtname1.Visible:=false;
      txtname.Visible:=true;
    end;
//--------------------------------------------------------------------------------------------
TPZS(Sender);//调用显示图片总数函数
end;

procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
//当前后浏览的时候
txtpath.Clear;//清空里面的内容{图片的路径}
txtname1.Visible:=false;//不可用,不可见{图片的名称}
txtname.Visible:=true;//可用,可见{图片的名称}
end;

procedure TForm1.TPZS(Sender: TObject);
begin
//显示图片总数
if (table1.RecordCount<1)then
  begin
    labTPZS.Caption:='0 张';
  end
else
  begin
    labTPZS.Caption:=inttostr(table1.Recordset.RecordCount)+'张';//"把BMP图像存取到数据库中"窗体上的"图片总数"
    formtpcz.lblTPZS.Caption:='库中共有图片:'+inttostr(table1.Recordset.RecordCount)+'张';//"图片查找"窗体上的"库中共有图片:"
    FormTPCZ.RefreshTableClick(Sender);//调用"图片查找窗体"上的刷新表函数
  end;
end;

procedure TForm1.tpczClick(Sender: TObject);
begin
  //图片查找菜单按钮
  if (table1.RecordCount<>0) then//判断库中是否有图片,如果有显示"图片查找窗体",否则弹出提示
    begin
      formtpcz.ShowModal;
    end
  else
    begin
      if (application.MessageBox('在库中没有图片,请您添加图片!','SUER开发小组',mb_ok+mb_iconinformation)=mrok) then
        begin
          Button1Click(Sender);//调用打开且保存BMP图像按钮
        end;
    end;
end;

procedure TForm1.tpgmClick(Sender: TObject);
begin
//图片改名菜单按钮
if (table1.RecordCount<>0) then //判断库中是否有图片,如果有显示"图片改名窗体"
  begin
    TPGMForm.ShowModal;
  end
else
  begin
    application.MessageBox('在库中没有图片,无法给图片改名!','SUER开发小组',mb_ok+mb_iconinformation);
  end;
end;

procedure TForm1.bbllClick(Sender: TObject);
begin
//报表浏览菜单按钮
table1.Active:=true;
if table1.RecordCount>0 then
   begin
     bbllform.QuickRep1.ReportTitle:='报表浏览';//在报表的标题样上显示"报表浏览"
     bbllForm.QuickRep1.PreviewModal;
   end
else
   application.MessageBox('没有找到可浏览的记录.','SUER开发小组',mb_ok+mb_iconasterisk);
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
//退出记录本菜单按钮
//退出整个程序(带有询问)
if application.MessageBox('确定要退出本系统吗?    ','SUER开发小组',mb_yesno+mb_iconquestion)=mryes then
  begin
    application.Terminate;
  end
else
  begin
    abort;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -