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

📄 89.htm

📁 水木清华的BBS文章
💻 HTM
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://bbs.tsinghua.edu.cn"><font face="黑体"><big><big>水木清华★</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         Delphi编程                            (BM: strayli FlyingBoy)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="454"> <p align="center">[<a href="index.htm">回到开始</a>][<a href="15.htm">上一层</a>][<a href="90.htm">下一篇</a>]
<hr><p align="left"><small>发信人: strayli (stray), 信区: Delphi <br>

标  题:   A Technical View of Borland MIDAS Part II (5) <br>

发信站: BBS 水木清华站 (Thu Nov 12 22:17:45 1998) WWW-POST <br>

  <br>

The Briefcase Model <br>

  <br>

  <br>

The briefcase model depends on two methods of TClientDataSet called <br>

LoadFromFile and SaveToFile: <br>

  <br>

CustomerClientDataSet.SaveToFile('Customer.dta'); <br>

  <br>

  <br>

  <br>

CustomerClientDataSet.LoadFromFile('Customer.dta'); <br>

  <br>

If you have two tables you want to save, then you should save and read them <br>

both to separate files: <br>

  <br>

procedure TForm1.BriefcaseSave1Click(Sender: TObject); <br>

  <br>

begin <br>

  <br>

  <br>

CustomerClientDataSet.SaveToFile(CustomerFile); <br>

  <br>

OrdersClientDataSet.SaveToFile(OrdersFile); <br>

  <br>

end; <br>

  <br>

Clearly the act of saving and reading files from disk is trivial in the <br>

extreme. However, there are some additional points that you need to take into <br>

consideration to use the briefcase model properly. Most of these points will <br>

be covered in the next section on PacketRecords. <br>

  <br>

PacketRecords <br>

PacketRecords is a very important property of TClientDataSet which you need <br>

to spend some time contemplating. In the next few paragraphs I will discuss <br>

it from several angles. In particular, I will make several references to its <br>

importance when using the briefcase model. <br>

  <br>

To make the briefcase model work correctly it is probably best to make sure <br>

the files on the server are not arranged in a one to many relationship and <br>

that you have set the PacketRecords property on both the ClientDataSets to <br>

-1. Setting PacketRecords to 0 brings down the metadata, setting it to -1 <br>

brings down all the data, and setting it to some positive number n brings <br>



down n records per request. <br>

  <br>

If you have already gotten the metadata for a dataset, then setting <br>

PacketRecords to -1, or to some positive number other than zero, will only <br>

retrieve data. However, if you have not gotten the metadata, then setting <br>

PacketRecords to -1 or to some positive number other than zero, will retrieve <br>

both the metadata and the records. <br>

  <br>

If you want to use the briefcase model, then you usually want to bring down <br>

the whole dataset, which means you want to set PacketRecords to -1. (Of <br>

course, a query on a server could already filter a large portion of a table <br>

for you, but you would still want to set PacketRecords to -1 to retrieve all <br>

of the records from the query. ) <br>

  <br>

If you just want to establish a one to many relationship, and don't care <br>

about the briefcase model, then you will probably want to set PacketRecords <br>

to zero on the detail table and to -1 on the master table. These settings <br>

retrieve all the records from the master table but only the metadata for the <br>

detail table. Then internally, Delphi will call TClientDataSet.AppendData to <br>

bring down just those detail records that are needed when viewing one <br>

particular master record. This is great for many situations, but it is <br>

probably not what you want if you are using the briefcase model. Instead, <br>

probably not what you want if you are using the briefcase model. Instead, <br>

when using the briefcase model, you will usually set PacketRecords to -1 and <br>

the master detail will still be done, but the whole detail dataset will be <br>

available on the server at all times. This is obviously impractical when <br>

working with very large datasets. <br>

  <br>

Because this is such an important issue, I am going to show you how to write <br>

some code that allows you to fine tune this process. The following code <br>

represents a nonsensical case where you first retrieve the metadata and then <br>

retrieve the records. I say this is nonsensical because the metadata will be <br>

retrieved automatically the first time you access the data. However, assuming <br>

you had some reason to get the metadata first and then get all the records, <br>

you could write code that looks like this: <br>

  <br>

with ClientDataSet1 do begin <br>

  <br>

Close; <br>

  <br>

PacketRecords := 0; <br>

  <br>

Open; <br>

  <br>

PacketRecords := -1; <br>



  <br>

GetNextPacket; <br>

  <br>

end; <br>

  <br>

  <br>

  <br>

Or, if you wanted to be very fancy, you can study this code from Delphi guru <br>

Josh Dahlby: <br>

  <br>

var <br>

  <br>

RecsOut: Integer; <br>

  <br>

V: OleVariant; <br>

  <br>

begin <br>

  <br>

CustomerClientDataSet.Close; <br>

  <br>

V := CustomerClientDataSet.Provider.GetMetaData; <br>

  <br>

  <br>

CustomerClientDataSet.AppendData(V, False) <br>

  <br>

V := CustomerClientDataSet.Provider.GetRecords(-1,RecsOut); <br>

  <br>

CustomerClientDataSet.AppendData(V, True); <br>

  <br>

end; <br>

  <br>

  <br>

  <br>

In this case you first close the client dataset, then use the GetMetaData <br>

function to retrieve the metadata inside an OleVariant. At this time, there <br>

is not much you can do with the result of this function other than pass it <br>

directly to AppendData, or else start hacking away at it with a series of low <br>

level functions. However, in the future, it is reasonable to suppose that <br>

Borland may provide functions for easily accessing the information from the <br>

data packet that is stored in the OleVariant. <br>

  <br>

AppendData takes two parameters. The first is the data retrieved from the <br>

server, the second is whether or not you hit EOF when retrieving the data. <br>

Remember that you don't have to use either GetRecords or AppendData, and that <br>

you should normally use GetNextPacket. Furthermore, the simplest way to <br>



perform this operation is simply to call Open or to set Active to True. I've <br>

shown you GetNextPacket and AppendData simply so you can have more control <br>

over the process if you happen to need it. <br>

  <br>

  <br>

-- <br>

※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.38.79.111] <br>

</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="15.htm">上一层</a>][<a href="90.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</body>
</html>

⌨️ 快捷键说明

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