DELPHI-如何使用记录的类型保存到文件

当您需要将一些复杂的记录类型保存到文件中时,可以使用以下代码:

{ header of admin file }
TRecFileAdmin = record
  sIdent              : string[15] ;
  dDateTo             : TDateTime;
end;
...
{ ---------------------------------------------------------------------------   Function generate admin file into _FileName file.   -------------------------------------------------------------------------- }
function GenerateAdminFile( _sFileName : string ) : boolean;
var
  f : TFile;
  recFileAdmin : TRecFileAdmin;
begin
  result := false;

  try
    try
      { every time establish new }f := TFile.Create( _sFileName, true );{ three day validity }FillChar( recFileAdmin, sizeof( recFileAdmin ), 0 );
      recFileAdmin.sIdent  := gcsIdent;
      recFileAdmin.dDateTo := Now + 3;  
      f.FileWrite( recFileAdmin, sizeof( recFileAdmin ) );
    except
      on E : exception do
        begin
          doError( ERROR_SAVE, [ 'A9Admin.GenerateAdmin()', E.Message ] );
          exit;
        end;
    end;
  finally
    f.free;
  end;

  result := true;
end;
联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678