如何以流方式在这个记录集结构中加上参数对文件进行操作
下面这个数据结构如下: 
type        //定义记录集[结构] 
    studentrecord=record 
    xh,xm:string[8];        //学号,姓名 
    yw,sx:integer;        //定义科目 
    //zp  ;  //这是个图片JPG文件
end; 
基本的操作: 新增 添加 插入 删除 更新等
//===================================================
就是将这个结构如何定义成流方式

解决方案 »

  1.   

    unit persrec;
    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.
      

  2.   

    iseekcode
    请问一下,你为什么没有引用图片呀?????????/
      

  3.   

    type        //定义记录集[结构] 
        studentrecord=record 
        xh,xm:string[8];        //学号,姓名 
        yw,sx:integer;        //定义科目 
        //zp  ;  //这是个图片JPG文件
        zp:TJPEGImage;   
    end; 
    我想在这个记录集结构中引用图片变量,在写入文件时将所有的信息转换成流
    再写入文件中...................
      

  4.   

    二楼只是一个例子。
    TPersonRec的内容可以更改。
    这个类完成了流化读写,很实用的,只是相见恨晚。
    我是最近翻D5开发人员指南时看到的。楼主像这样:
    xh,xm:string[8];        //学号,姓名 
    yw,sx:integer;          //定义科目
    既然不是变体声明,应该分开:
    xh:integer;
    xm:string[8];
    ...另外,声明最好T开头: 
    Tstudentrecord=record
    如果需要,还可以声明一个:
    Pstudentrecord:^studentrecord;
    有可能用得着
      

  5.   

    文件内容结构如下: 
    就是数据类型不统一呀 
    [A0000001.JPG+56+sdfsdfsd] 
    图片文件+图片长度+图片内容 
    字符型 +数据型  +二进制型