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

📄 objaccessu.pas

📁 source for card readers
💻 PAS
字号:
unit ObjAccessU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls;

type
  TfrmAccessObject = class(TForm)
    lblAccNo: TLabel;
    lblName: TLabel;
    btnCreate: TButton;
    btnDelete: TButton;
    gpbCName: TGroupBox;
    edtCName: TEdit;
    gpbAccNo: TGroupBox;
    edtAccNo: TEdit;
    lstClients: TListBox;
    lblIndex: TLabel;
    procedure btnCreateClick(Sender: TObject);
    procedure lstClientsClick(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
  end;

var
  frmAccessObject: TfrmAccessObject;

implementation

uses ClientU;

{$R *.dfm}

{TfrmObjList}

procedure TfrmAccessObject.btnCreateClick(Sender: TObject);
var
  NewClient: TClient;
  Dummy: integer;
begin
  // Exit if input invalid
  if (edtCName.Text = '') or (not TryStrToInt(edtAccNo.Text, Dummy)) then
  begin
    ShowMessage ('Please enter a valid name and/or number');
    Exit;
  end;

  NewClient := TClient.Create (edtCName.Text, edtAccNo.Text);

  // Add object to ListBox and create an additional reference
  lstClients.AddItem(NewClient.CName, NewClient);

  edtCName.Clear;
  edtAccNo.Clear;
  edtCName.SetFocus;
end; // end procedure TfrmAccessObject.btnAddClick

procedure TfrmAccessObject.lstClientsClick(Sender: TObject);
var
  CurrentClient: TClient;
begin
  lblIndex.Caption := 'Item index: ' +
                      IntToStr (lstClients.ItemIndex);
  CurrentClient := lstClients.Items.Objects [lstClients.ItemIndex]
                                                         as TClient;
  lblName.Caption := 'Name: ' + CurrentClient.CName;
  lblAccNo.Caption := 'Acc No: ' + CurrentClient.AccNo;
end;  // end procedure TfrmAccessObject.lstClientsClick

procedure TfrmAccessObject.btnDeleteClick(Sender: TObject);
var
  CurrentClient: TClient;
begin
  if lstClients.ItemIndex < 0 then
  begin
    ShowMessage ('No client selected');
    exit;
  end;

  if MessageDlg ('Delete selected client?', mtConfirmation,
      mbOkCancel, 0) <> mrOK then	// confirm deletion
    exit;

  // OK to delete so go ahead
  CurrentClient := lstClients.Items.Objects [lstClients.ItemIndex]
      as TClient;
  FreeAndNil(CurrentClient);
  {CurrentClient.Free;  // alternative to previous line }
  lstClients.DeleteSelected;

  lblIndex.Caption := 'Item index';	// update display
  lblName.Caption := 'Name';
  lblAccNo.Caption := 'Acc No';
end;  // end procedure TfrmAccessObject.btnDeleteClick

end. // end unit ObjAccessU

⌨️ 快捷键说明

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