unit CustomDoc; interface uses Classes, SysUtils; type TProjectFile = class(TComponent) private FID: Integer; FNewID: Integer; FFlag: Integer; FGatherID: Integer; FProjName: string; FFullPath: string; public property NewID: Integer read FNewID write FNewID; property FullPath: string read FFullPath write FFullPath; published property ID: Integer read FID write FID; property Flag: Integer read FFlag write FFlag; property GatherID: Integer read FGatherID write FGatherID; property ProjName: string read FProjName write FProjName; end; TAddProjectProc = procedure (aProjFile: TProjectFile; aProjList: TList; var aFullPath: string) of object; TCustomProjectDoc = class public class procedure ImportProjects(const aFileName: string; aAddProc: TAddProjectProc); class procedure ExportProjects(const aFileName: string; aFileList: TList); end; implementation { TCustomProjectDoc } class procedure TCustomProjectDoc.ExportProjects(const aFileName: string; aFileList: TList); var iValue: Integer; iLoop: Integer; strFilePath: string; ProjFile: TProjectFile; FileStream: TFileStream; ProjectStream: TFileStream; begin FileStream := TFileStream.Create(aFileName, fmCreate); try iValue := aFileList.Count; // 文件个数 FileStream.Write(iValue, SizeOf(iValue)); for iLoop := 0 to aFileList.Count - 1 do begin ProjFile := TProjectFile(aFileList.List^[iLoop]); strFilePath := ProjFile.FullPath; // 项目信息 FileStream.WriteComponent(ProjFile); // 文件大小 ProjectStream := TFileStream.Create(ProjFile.FullPath, fmOpenRead); iValue := ProjectStream.Size; FileStream.Write(iValue, SizeOf(iValue)); // 文件内容 FileStream.CopyFrom(ProjectStream, iValue); ProjectStream.Free; end; finally FileStream.Free; end; end; class procedure TCustomProjectDoc.ImportProjects(const aFileName: string; aAddProc: TAddProjectProc); var iValue: Integer; iLoop: Integer; ProjList: TList; iFileSize: Integer; strFilePath: string; ProjFile: TProjectFile; FileStream: TFileStream; ProjectStream: TFileStream; begin ProjList := TList.Create; FileStream := TFileStream.Create(aFileName, fmOpenRead); try // 文件个数 FileStream.Read(iValue, SizeOf(iValue)); for iLoop := 0 to iValue - 1 do begin // 项目信息 ProjFile := TProjectFile.Create(nil); FileStream.ReadComponent(ProjFile); aAddProc(ProjFile, ProjList, strFilePath); // 文件大小 FileStream.Read(iFileSize, SizeOf(iFileSize)); // 文件内容 ProjectStream := TFileStream.Create(strFilePath, fmCreate); ProjectStream.CopyFrom(FileStream, iFileSize); ProjectStream.Free; end; finally FileStream.Free; for iLoop := 0 to ProjList.Count - 1 do TProjectFile(ProjList.List^[iLoop]).Free; ProjList.Free; end; end; end.