【delphi开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了delphi开源代码-frm_ADO.pas的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
unit frm_ADO;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls,ADOInt, XPMan;
type
TfrmADO = class(TForm)
GBxList: TGroupBox;
EdID: TEdit;
EdPartNumber: TEdit;
EdPartName: TEdit;
EdCreateDate: TEdit;
LbId: TLabel;
LbNumber: TLabel;
LBPart: TLabel;
Label1: TLabel;
GBxMemo: TGroupBox;
MoMemo: TMemo;
BtnFirst: TButton;
BtnPrio: TButton;
BtnNext: TButton;
BtnLast: TButton;
BtnClose: TButton;
procedure FormCreate(Sender: TObject);
procedure BtnCloseClick(Sender: TObject);
procedure BtnFirstClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
Adoc,AdoR:Variant;
procedure ShowDate;
Procedure OpenData;
{ Private declarations }
public
{ Public declarations }
end;
var
frmADO: TfrmADO;
implementation
{$R *.dfm}
Procedure TFrmADO.OpenData;
begin
Ador.Open('select * from TB_dePartMent',adoc,adOpenStatic,AdLockOpti
mistic,adCmdText);
end;
procedure TfrmADO.ShowDate;
begin
try
EdiD.text := vartostr(Ador.Fields[0].Value);
EdPartNumber.Text:=vartostr(Ador.Fields[1].Value);
EdPartName.Text:=vartostr(Ador.Fields[2].Value);
EdCreateDate.Text:=vartostr(Ador.Fields[3].Value);
MoMemo.Text:=vartostr(Ador.Fields[4].Value);
except
exit;
end;
end;
procedure TfrmADO.FormCreate(Sender: TObject);
var
S:String;
begin
Adoc:=CreateOleObject('ADODB.Connection');
S:='Provider=SQLOLEDB.1;Pass
word="";Persist Security Info=True;User ID=sa;Initial Catalog=
DelphiClassical200';
Adoc.open(s);
Ador:=CreateOleObject('ADODB.RecordSet');
Ador.ActiveConnection:=Adoc;
end;
procedure TfrmADO.BtnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmADO.BtnFirstClick(Sender: TObject);
begin
case TButton(Sender).Tag of
1,2:
begin
if ADor.Bof then
begin
showmessage('已经是第一条记录了!')
end
else
begin
if TButton(Sender).Tag = 1 then
begin
ADOr.MoveFirst;
ShowDate;
Ador.MovePrevious;
end
else
begin
Ador.MovePrevious;
ShowDate;
end;
end;
end;
3,4: begin
if ADor.Eof then
showmessage('已经是最后一条记录了!')
else
begin
if TButton(Sender).Tag = 4 then
begin
ADOr.MoveLast;
ShowDate;
Ador.MoveNext;
end
else
begin
Ador.MoveNext;
ShowDate;
end;
end
End;
end;
end;
procedure TfrmADO.FormShow(Sender: TObject);
begin
Opendata;
ShowDate;
end;
end.