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

📄 tpgmunit2.pas

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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, ExtCtrls, Buttons, Menus, ExtDlgs;

type
  TTPGMForm = class(TForm)
    lstTPGM: TListBox;
    ADOTPMGTable: TADOTable;
    ADOTPMGQuery: TADOQuery;
    DataTPMGSource: TDataSource;
    penal1: TPanel;
    imageTPGM: TImage;
    lblXGTPMC: TLabel;
    txtXGTPMC: TEdit;
    btnQD: TSpeedButton;
    PopupMenu1: TPopupMenu;
    bcctp: TMenuItem;
    SavePictureDialog1: TSavePictureDialog;
    procedure FormShow(Sender: TObject);
    procedure lstTPGMClick(Sender: TObject);
    procedure btnQDClick(Sender: TObject);
    procedure RefreshTableClick(Sender: TObject);
    procedure bcctpClick(Sender: TObject);//刷新表

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  TPGMForm: TTPGMForm;

implementation

uses TPCZUnit2, Unit1;

{$R *.dfm}

procedure TTPGMForm.FormShow(Sender: TObject);
begin
lstTPGM.Clear;//清空列表框中的内容
RefreshTableClick(Sender);//刷新表
//------------------------------------------------------------------------------
//把image表的"name"里的内容全部在"lstTPGM"列表中,列出来
   with ADOTPMGTable do
    begin
      First;
      while not Eof do
        begin
          lstTPGM.Items.Add(FieldByName('Name').AsString);
          Next;
        end;
    end;
//------------------------------------------------------------------------------
end;

procedure TTPGMForm.lstTPGMClick(Sender: TObject);
var
mem:TStream;
bmp:TBitmap;
begin
//选择列表框中的图片名称同时在"ImageTPCZ"图片框中显示出来
  with ADOTPMGTable do
    begin
      First;
      while not Eof do
          begin
          if FieldByName('Name').AsString=lstTPGM.Items[lstTPGM.ItemIndex] then
            break;
            Next;
          end;
        bmp:=TBitmap.Create;
        mem:=CreateBlobStream(FieldByName('Data'),bmRead);//读取"data"字段中的图片
        mem.Position:=0;
        bmp.LoadFromStream(mem);
        self.imageTPGM.Picture.Assign(bmp);
        bmp.Free;
        mem.Free;
    end;
    txtXGTPMC.Text:=lstTPGM.Items.Strings[lstTPGM.ItemIndex];//存放要修改的图片的名称
end;

procedure TTPGMForm.btnQDClick(Sender: TObject);
begin
  //确定按钮
  with ADOTPMGTable do
    begin
      if (txtXGTPMC.text<>'') then //判断文本框中的内容是否为空,如果是则提示
        begin
          if (application.MessageBox('确定要修改吗?     ','SUER开发小组',mb_yesno+mb_iconquestion)=mryes) then
            if (locate('name',txtXGTPMC.Text,[])) then //判断在库中是否有与目前修改的图片的名称相同的记录,如果有则提示
              begin
                application.MessageBox('修改失败,在库中存有同名的图片,请试别一个名称!     ','SUER开发小组',mb_ok+mb_iconquestion);
                abort;
              end
            else
              begin
                edit;
                FieldByName('Name').AsString:=txtXGTPMC.Text;
                application.MessageBox('修改成功!     ','SUER开发小组',mb_ok+mb_iconquestion);
                post;
                txtXGTPMC.Clear;//清空"修改名称"文本内容
                imageTPGM.Picture:=nil;//清空imageTPGM里面的图片
                RefreshTableClick(Sender);//刷新表
                FormShow(Sender);//图片名称更改后,把image表的"name"里的内容全部在"lstTPGM"列表中,列出来
              end;
        end
      else
        begin
          application.MessageBox('修改失败,请在左边的列表框中选择一张图片'+#13+'之后再修改图的名称!     ','SUER开发小组',mb_ok+mb_iconquestion);
          abort;
        end;
    end;
end;


procedure TTPGMForm.RefreshTableClick(Sender: TObject);
begin
//刷新表
{图片改名窗体上的}
ADOTPMGTable.Active:=false;
ADOTPMGTable.Active:=true;
//------------------------------------------------------------------------------
{把BMP图像存取到数据库中窗体上的}
form1.table1.Active:=false;
form1.table1.Active:=true;
//------------------------------------------------------------------------------
{图片查找窗体上的}
FormTPCZ.ADOTPCZTable.Active:=false;
FormTPCZ.ADOTPCZTable.Active:=true;
//------------------------------------------------------------------------------
end;

procedure TTPGMForm.bcctpClick(Sender: TObject);
begin
//保存此图片菜单按钮
if imageTPGM.Picture.Graphic = nil then //判断imageTPGM里面是否有图片,如果没有则提示
  begin
    application.MessageBox('保存失败,请在左边的列表框中选择一张图片'+#13+'之后再保存图片!     ','SUER开发小组',mb_ok+mb_iconquestion);
    abort;
  end
else
  begin
    if imageTPGM.Picture <> nil then
      begin
        if SavePictureDialog1.Execute then
          begin
            imageTPGM.Picture.SaveToFile(SavePictureDialog1.FileName+'.bmp');
            application.MessageBox('保存成功!     ','SUER开发小组',mb_ok+mb_iconquestion);
            txtXGTPMC.Clear;//清空"修改名称"文本内容
            imageTPGM.Picture:=nil;//清空imageTPGM里面的图片
          end;
      end;
  end;
end;

end.

⌨️ 快捷键说明

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