如何以流方式在这个记录集结构中加上参数对文件进行操作
下面这个数据结构如下:
type //定义记录集[结构]
studentrecord=record
xh,xm:string[8]; //学号,姓名
yw,sx:integer; //定义科目
//zp ; //这是个图片JPG文件
end;
基本的操作: 新增 添加 插入 删除 更新等
//===================================================
就是将这个结构如何定义成流方式
下面这个数据结构如下:
type //定义记录集[结构]
studentrecord=record
xh,xm:string[8]; //学号,姓名
yw,sx:integer; //定义科目
//zp ; //这是个图片JPG文件
end;
基本的操作: 新增 添加 插入 删除 更新等
//===================================================
就是将这个结构如何定义成流方式
解决方案 »
- DELPHI 控件属性用变量替换
- ACCESS数据库中设置了一数据类型为——自动编号的字段…………………………………………
- 贱卖智环财务软件的源码
- 谁知道哪里有WindowMediaPlayer组件编程的例程?
- 在delphi编程中如何能控制word的菜单和工具条?
- 如何将查询结果修改返回给数据库?
- 我们公司有一个网吧管理的程序服务端和客户端现在有人要买它的源码......试问可以卖多少?
- 哪位兄弟有人才网站(类似于www.51job.com)的可行性研究报告、需求分析说明书?我可出钱购买!
- 求票据打印--程序设计思路
- 急!请问用拨号网络连上异地服务器后,如何使两地数据库数据交换??
- 如何取得共享文件夹的本地路径
- 出点难题吧:如何找到指定dll的handle
interface
uses Classes, dialogs, sysutils;
type
// Define the record that will hold the person’s information.
TPersonRec = packed record
FirstName: String[20];
LastName: String[20];
MI: String[1];
BirthDay: TDateTime;
Age: Integer;
end;
// Create a descendant TFileStream which knows about the TPersonRec
TRecordStream = class(TFileStream)
private
function GetNumRecs: Longint;
function GetCurRec: Longint;
procedure SetCurRec(RecNo: Longint);
protected
function GetRecSize: Longint; virtual;
public
function SeekRec(RecNo: Longint; Origin: Word): Longint;
function WriteRec(const Rec): Longint;
function AppendRec(const Rec): Longint;
function ReadRec(var Rec): Longint;
procedure First;
procedure Last;
procedure NextRec;
procedure PreviousRec;
// NumRecs shows the number of records in the stream
property NumRecs: Longint read GetNumRecs;
// CurRec reflects the current record in the stream
property CurRec: Longint read GetCurRec write SetCurRec;
end;
implementation
function TRecordStream.GetRecSize:Longint;
begin
{ This function returns the size of the record that this stre
knows about (TPersonRec) }
Result := SizeOf(TPersonRec);
end;
function TRecordStream.GetNumRecs: Longint;
begin
// This function returns the number of records in the stream
Result := Size div GetRecSize;
end;function TRecordStream.GetCurRec: Longint;
begin
{ This function returns the position of the current record. We must
add one to this value because the file pointer is always at the
beginning of the record which is not reflected in the equation:
Position div GetRecSize }
Result := (Position div GetRecSize) + 1;
end;
procedure TRecordStream.SetCurRec(RecNo: Longint);
begin
{ This procedure sets the position to the record in the stream
specified by RecNo. }
if RecNo > 0 then
Position := (RecNo - 1) * GetRecSize
else
Raise Exception.Create(‘Cannot go beyond beginning of file.’);
end;
function TRecordStream.SeekRec(RecNo: Longint; Origin: Word): Longint;
begin
{ This function positions the file pointer to a location
specified by RecNo }{ NOTE: This method does not contain error handling to determine if this
operation will exceed beyond the beginning/ending of the streamed
file }Result := Seek(RecNo * GetRecSize, Origin);
end;
function TRecordStream.WriteRec(Const Rec): Longint;
begin
// This function writes the record Rec to the stream
Result := Write(Rec, GetRecSize);
end;
function TRecordStream.AppendRec(Const Rec): Longint;
begin
// This function writes the record Rec to the stream
Seek(0, 2);
Result := Write(Rec, GetRecSize);
end;
function TRecordStream.ReadRec(var Rec): Longint;
begin
{ This function reads the record Rec from the stream and
positions the pointer back to the beginning of the record }
Result := Read(Rec, GetRecSize);
Seek(-GetRecSize, 1);
end;
procedure TRecordStream.First;
begin
{ This function positions the file pointer to the beginning
of the stream }
Seek(0, 0);
end;procedure TRecordStream.Last;
begin
// This procedure positions the file pointer to the end of the stream
Seek(0, 2);
Seek(-GetRecSize, 1);
end;
procedure TRecordStream.NextRec;
begin
{ This procedure positions the file pointer at the next record
location }
{ Go to the next record as long as it doesn’t extend beyond theend of the file. }
if ((Position + GetRecSize) div GetRecSize) = GetNumRecs then
raise Exception.Create(‘Cannot read beyond end of file’)
else
Seek(GetRecSize, 1);
end;
procedure TRecordStream.PreviousRec;
begin
{ This procedure positions the file pointer to the previous record
in the stream }
{ Call this function as long as we don’t extend beyond the
beginning of the file }
if (Position - GetRecSize >= 0) then
Seek(-GetRecSize, 1)
else
Raise Exception.Create(‘Cannot read beyond beginning of the file.’);
end;
end.
请问一下,你为什么没有引用图片呀?????????/
studentrecord=record
xh,xm:string[8]; //学号,姓名
yw,sx:integer; //定义科目
//zp ; //这是个图片JPG文件
zp:TJPEGImage;
end;
我想在这个记录集结构中引用图片变量,在写入文件时将所有的信息转换成流
再写入文件中...................
TPersonRec的内容可以更改。
这个类完成了流化读写,很实用的,只是相见恨晚。
我是最近翻D5开发人员指南时看到的。楼主像这样:
xh,xm:string[8]; //学号,姓名
yw,sx:integer; //定义科目
既然不是变体声明,应该分开:
xh:integer;
xm:string[8];
...另外,声明最好T开头:
Tstudentrecord=record
如果需要,还可以声明一个:
Pstudentrecord:^studentrecord;
有可能用得着
就是数据类型不统一呀
[A0000001.JPG+56+sdfsdfsd]
图片文件+图片长度+图片内容
字符型 +数据型 +二进制型