全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2403
推到 Plurk!
推到 Facebook!

DataSetProvider1.GetRecords(......)如何取後面的n個數據包?

答題得分者是:pcplayer99
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-09 17:01:21 IP:211.148.xxx.xxx 未訂閱
連接如下: ADOConnection1<--?ADOQuery1<--?DataSetProvider1 通過DataSetProvider1取得的數據包放到ClientDataSet1中。 var RecsOut: integer; begin ...... ClientDataSet1.Close; ClientDataSet1.Data := DataSetProvider1.GetRecords(5, RecsOut, Byte(Options)); Edit1.Text := inttostr(RecsOut); ClientDataSet1.Open; ...... end; 但每次取得的數據包居然都是從第一條記錄開始, 請問如何依次5條5條的取完ADOQuery1中的資料集? 誰能給個例子看看?
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
pcplayer99
尊榮會員


發表:146
回覆:790
積分:632
註冊:2003-01-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-09 17:15:50 IP:61.141.xxx.xxx 未訂閱
引言: 連接如下: ADOConnection1<--?ADOQuery1<--?DataSetProvider1 通過DataSetProvider1取得的數據包放到ClientDataSet1中。 var RecsOut: integer; begin ...... ClientDataSet1.Close; ClientDataSet1.Data := DataSetProvider1.GetRecords(5, RecsOut, Byte(Options)); Edit1.Text := inttostr(RecsOut); ClientDataSet1.Open; ...... end; 但每次取得的數據包居然都是從第一條記錄開始, 請問如何依次5條5條的取完ADOQuery1中的資料集? 誰能給個例子看看?
因为APP SERVER是无状态的,它不会帮你记住你上一次取到了第几条。因此,你必须自己送当前需要的记录的KEY值给APP SERVER,让APP SERVER把游标走到那条记录。
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-09 20:33:08 IP:219.133.xxx.xxx 未訂閱
按照http://bdn.borland.com/article/0,1410,20846,00.html上面所說做了如下改正,但還是不行: procedure TForm1.Button1Click(Sender: TObject); begin ClientDataSet1.Close; ClientDataSet1.Data := DataSetProvider1.GetRecords(16, RecsOut, byte(Options)); Edit1.Text := IntToStr(recsout); ClientDataSet1.Open; end; procedure TForm1.DataSetProvider1BeforeGetRecords(Sender: TObject; var OwnerData: OleVariant); begin with Sender as TDataSetProvider do begin DataSet.Open; if not VarIsEmpty(OwnerData) then DataSet.Locate('id', OwnerData, []) else DataSet.First; end; end; procedure TForm1.DataSetProvider1AfterGetRecords(Sender: TObject; var OwnerData: OleVariant); begin with Sender as TDataSetProvider do begin OwnerData := Dataset.FieldValues['id']; DataSet.Close; end; end;
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
pcplayer99
尊榮會員


發表:146
回覆:790
積分:632
註冊:2003-01-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-10 13:15:29 IP:61.141.xxx.xxx 未訂閱
你应该看看 DELPHI 的 HELP,里面是这样说的: ------------------------------------------------- OwnerData is the custom information defined by the application developer. In client dataset 揃eforeXXX?events, this parameter is for output only so that it can be sent to the provider. In provider 揃eforeXXX?events, this parameter enters as information sent by the client dataset 揃eforeXXX?event and returns the information passed to the provider 揂fterXXX?event. In the provider 揂fterXXX?event, this parameter enters as information from the provider (or client dataset) 揃eforeXXX?event and returns the information that is passed to the client dataset 揂fterXXX?event. In client dataset 揂fterXXX?events, this parameter is for input only, and contains the information returned by the provider. Note: OwnerData is an OleVariant. As such, it can contain a single data value, a ------------------------------------------- 实际上,你应该在 ClientDataSet.BeforeGetRecords里,把当前ClientDataSet的末尾的KEY 使用 OwnerData: OleVariant 传送给 APP SERVER 在 App Server 里,在 DataSetProvider.BeforeGetRecords(Sender: TObject; var OwnerData: OleVariant); 里的 OwnerData 来取得这个 KEY ,然后用这个 KEY 来定位DataSetProvider.DataSet。 实际上,这里的 OwnerData 就是用来在 Client 和 APP SERVER之间传递你自己想传递的任何数据用的。仔细看看上面的 HELP 吧。
pcplayer99
尊榮會員


發表:146
回覆:790
積分:632
註冊:2003-01-21

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-10 13:46:14 IP:61.141.xxx.xxx 未訂閱
DELPHI7 HELP 里的 sample: ---------------------------- This example shows how to use the BeforeGetRecords event handler (a TRemoteEventType value) to send the provider information it needs for incremental data fetching. Before fetching the next data packet, the client dataset packages up the key value of the last record so that the provider knows where to begin the next data packet. It also sends some application-specific information, which is stored in Memo1. procedure TForm1.ClientDataSet1BeforeGetRecords(Sender: TObject; var OwnerData: OleVariant); var LastValue: OleVariant; CDSClone:ClientDataSet; begin if ClientDataSet1.Active then begin CDSClone := ClientDataSet.Create(Form1); try CDSClone.CloneCursor(ClientDataSet1, True); { turn off FetchOnDemand so that the clone only fetches the last LOCAL record } CDSClone.FetchOnDemand := False; CDSClone.Last; LastValue := CDSClone.Fields[0].AsString; CDSClone.Close; finally CDSClone.Free; end; end else LastValue := NULL; OwnerData := VarArrayOf([Memo1.Lines.Text, LastValue]); end;
系統時間:2024-04-19 2:11:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!