📄 friendsunit.~pas
字号:
unit FriendsUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, ToolWin, ComCtrls, Buttons;
type
TFriendsForm = class(TForm)
StatusBar1: TStatusBar;
CoolBar1: TCoolBar;
DBGrid1: TDBGrid;
AddButton: TSpeedButton;
EditButton: TSpeedButton;
DeleteButton: TSpeedButton;
SearchButton: TSpeedButton;
RefreshButton: TSpeedButton;
ExitButton: TSpeedButton;
procedure DeleteButtonClick(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
procedure EditButtonClick(Sender: TObject);
procedure SearchButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
procedure RefreshButtonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FriendsForm: TFriendsForm;
implementation
uses DataUnit,PublicUnit,FriendsAddUnit,FriendsEditUnit,FriendsQryUnit;
{$R *.dfm}
procedure TFriendsForm.DeleteButtonClick(Sender: TObject);
var
DelName,DelId,SQLText:string;
begin
If Trim(DBGrid1.Fields[0].AsString) = '' then Exit;
DelId := DataForm.qrySource.FieldByName('Id').AsString;
DelName := Trim(DataForm.qrySource.FieldByName('Name').AsString);
SQLText := DataForm.qrySource.SQL.Text;
If MessageDlg('确实要删除“'+DelName+'”的信息吗?',mtConfirmation,[mbyes,mbno],0) = mryes then
begin
ExecSQL(DataForm.qryEdit,'Delete From myfriends Where Id = '+DelId+'');
OpenSQL(DataForm.qrySource,SQLText);
StatusBar1.Panels[1].Text := IntToStr(DataForm.qrySource.RecordCount);
end;
end;
procedure TFriendsForm.AddButtonClick(Sender: TObject);
begin
Application.CreateForm(TFriendsAddForm,FriendsAddForm);
try
FriendsAddForm.ShowModal;
finally
FriendsAddForm.Free;
end;
StatusBar1.Panels[1].Text := IntToStr(DataForm.qrySource.RecordCount);
end;
procedure TFriendsForm.EditButtonClick(Sender: TObject);
begin
if DBGrid1.Fields[0].AsString = '' then Exit;
Application.CreateForm(TFriendsEditForm,FriendsEditForm);
try
FriendsEditForm.ShowModal;
finally
FriendsEditForm.Free;
end;
end;
procedure TFriendsForm.SearchButtonClick(Sender: TObject);
begin
Application.CreateForm(TFriendsQryForm,FriendsQryForm);
try
FriendsQryForm.ShowModal;
finally
FriendsQryForm.Free;
end;
StatusBar1.Panels[1].Text := IntToStr(DataForm.qrySource.RecordCount);
end;
procedure TFriendsForm.ExitButtonClick(Sender: TObject);
begin
close;
end;
procedure TFriendsForm.RefreshButtonClick(Sender: TObject);
var
SQLText:String;
begin
SQLText := 'Select * From myfriends Order by Id DESC';
OpenSQL(DataForm.qrySource,SQLText);
StatusBar1.Panels[1].Text := IntToStr(DataForm.qrySource.RecordCount);
end;
procedure TFriendsForm.FormShow(Sender: TObject);
begin
RefreshButton.Click;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -