边
边城
Unregistered / Unconfirmed
GUEST, unregistred user!
<Delphi 5.x 分布式多层应用系统篇>中讲到的一段,是很有用,但不知哪位已把它写成通用性强些的代码,如我们一段是用一个GRID现来显示的,那么当我数据到了最后一条时,系统要去取下一段数据.这时我总不能再用一个<MORE>BUTTON来实现吧.那么这时在BUTTON中的代码应放在哪里来实现此功能呢.
(鱼和熊手掌可兼得)代码如下:
--------CLIENT
unit U_client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, Wwdbigrd, Wwdbgrid, DB, DBClient, MConnect, SConnect,
StdCtrls, Buttons;
type
TForm1 = class(TForm)
SocketConnection1: TSocketConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
wwDBGrid1: TwwDBGrid;
BitBtn1: TBitBtn;
EdtRecodno: TEdit;
edttime: TEdit;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
function getkeyfieldvalue(sender:tobject):Olevariant;
procedure GetNextPck(dataset:TclientDataset);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
vownerdata:Olevariant;
btrueeof:boolean;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
SocketConnection1.Connected:=true;
ClientDataSet1.Open;
btrueeof:=false;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Dstart,Dend:integer;
abk:Tbookmark;
begin
Dstart:=gettickcount();
try
if (not bTrueEof) then
begin
try
abk:=clientdataset1.GetBookmark;
if (ClientDataSet1.GetNextPacket<clientDataset1.PacketRecords) then
btrueeof:=true;
clientdataset1.Last;
vownerdata:=clientdataset1.fieldbyname('cpbh').value;
clientdataset1.GotoBookmark(abk);
clientdataset1.Next;
finally
clientdataset1.FreeBookmark(abk);
end;
end;
except
on exception do;
end;
EdtRecodno.text:=IntTostr(clientdataset1.recordcount);
Dend:=gettickcount;
EdtRecodno.text:=inttostr(clientdataset1.recordcount);
edttime.text :=floattostr((Dend-Dstart)/1000) +'S';
end;
procedure TForm1.ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
IF ((VARISEMPTY(vownerdata)) or varisnull(vownerdata) ) then
vownerdata:=getkeyfieldvalue(sender);
ownerdata:=vownerdata;
end;
function TForm1.getkeyfieldvalue(sender: tobject): Olevariant;
var
CurRecord:tbookmark;
begin
try
with Sender as Tclientdataset do
begin
CurRecord:=GetBookmark;
try
Last;
result:=FieldByname('CPBH').value;
GotoBookmark(CurRecord);
finally
freebookmark(CurRecord);
end;
end;
except
on exception do;
end;
end;
procedure TForm1.GetNextPck(dataset: TclientDataset);
var
Dstart,Dend:integer;
abk:Tbookmark;
begin
Dstart:=gettickcount();
try
if (not bTrueEof) then
begin
try
abk:=dataset.GetBookmark;
if (dataset.GetNextPacket<dataset.PacketRecords) then
btrueeof:=true;
dataset.Last;
vownerdata:=dataset.fieldbyname('cpbh').value;
dataset.GotoBookmark(abk);
dataset.Next;
finally
dataset.FreeBookmark(abk);
end;
end;
except
on exception do;
end;
end;
end.
--------------SERVER
procedure TTestData.DataSetProvider1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
with tDataSetProvider(sender) do
begin
dataset.Open;
dataset.Locate('CPBH',Ownerdata,[]);
dataset.Next;
end;
end;
有建设性建议或代码的,给分.
(鱼和熊手掌可兼得)代码如下:
--------CLIENT
unit U_client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, Wwdbigrd, Wwdbgrid, DB, DBClient, MConnect, SConnect,
StdCtrls, Buttons;
type
TForm1 = class(TForm)
SocketConnection1: TSocketConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
wwDBGrid1: TwwDBGrid;
BitBtn1: TBitBtn;
EdtRecodno: TEdit;
edttime: TEdit;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
function getkeyfieldvalue(sender:tobject):Olevariant;
procedure GetNextPck(dataset:TclientDataset);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
vownerdata:Olevariant;
btrueeof:boolean;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
SocketConnection1.Connected:=true;
ClientDataSet1.Open;
btrueeof:=false;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Dstart,Dend:integer;
abk:Tbookmark;
begin
Dstart:=gettickcount();
try
if (not bTrueEof) then
begin
try
abk:=clientdataset1.GetBookmark;
if (ClientDataSet1.GetNextPacket<clientDataset1.PacketRecords) then
btrueeof:=true;
clientdataset1.Last;
vownerdata:=clientdataset1.fieldbyname('cpbh').value;
clientdataset1.GotoBookmark(abk);
clientdataset1.Next;
finally
clientdataset1.FreeBookmark(abk);
end;
end;
except
on exception do;
end;
EdtRecodno.text:=IntTostr(clientdataset1.recordcount);
Dend:=gettickcount;
EdtRecodno.text:=inttostr(clientdataset1.recordcount);
edttime.text :=floattostr((Dend-Dstart)/1000) +'S';
end;
procedure TForm1.ClientDataSet1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
IF ((VARISEMPTY(vownerdata)) or varisnull(vownerdata) ) then
vownerdata:=getkeyfieldvalue(sender);
ownerdata:=vownerdata;
end;
function TForm1.getkeyfieldvalue(sender: tobject): Olevariant;
var
CurRecord:tbookmark;
begin
try
with Sender as Tclientdataset do
begin
CurRecord:=GetBookmark;
try
Last;
result:=FieldByname('CPBH').value;
GotoBookmark(CurRecord);
finally
freebookmark(CurRecord);
end;
end;
except
on exception do;
end;
end;
procedure TForm1.GetNextPck(dataset: TclientDataset);
var
Dstart,Dend:integer;
abk:Tbookmark;
begin
Dstart:=gettickcount();
try
if (not bTrueEof) then
begin
try
abk:=dataset.GetBookmark;
if (dataset.GetNextPacket<dataset.PacketRecords) then
btrueeof:=true;
dataset.Last;
vownerdata:=dataset.fieldbyname('cpbh').value;
dataset.GotoBookmark(abk);
dataset.Next;
finally
dataset.FreeBookmark(abk);
end;
end;
except
on exception do;
end;
end;
end.
--------------SERVER
procedure TTestData.DataSetProvider1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
with tDataSetProvider(sender) do
begin
dataset.Open;
dataset.Locate('CPBH',Ownerdata,[]);
dataset.Next;
end;
end;
有建设性建议或代码的,给分.