unit MCAD_MI1201_FileOutput; interface USES SysUtils, Classes, MITypes, Registry,MCAD_MI1201_Thread_Types; type tMsDataFileType=(msdftText); tMsDataFileFlag=(msdffOverride, msdffCommentAtBegin, msdffAddAutoComment, msdffAddComment, msdffWriteStrings); tMsDataFileFlags=set of tMsDataFileFlag; tMsDataTextFileFormat=record Format: TFloatFormat; Precision, Digits: word; ColumnWidth:integer; NumberSeparator, CommentBegin,CommentEnd, CommentLineBegin{,CommentLineEnd}:String; end; tMsDataFileFormat=class(TObject) private prStream:TStream; prComment:tStringList; prMassMin,prMassMax:tMass; function MassMinGet:tMass; function MassMaxGet:tMass; procedure WriteSeriesTitleLineForStrings; procedure WriteSeriesTitleLineForColumns; public FileType:tMsDataFileType; Flags:tMsDataFileFlags; FileName:string; TextFile:tMsDataTextFileFormat; Series:tSeriesSet; WriteMassSeries:tSeriesSet; property Comment:tStringList read prComment; property MassMin:tMass read MassMinGet write prMassMin; property MassMax:tMass read MassMaxGet write prMassMax; function FullMassRange:boolean; constructor Create; destructor Destroy; override; procedure WriteComment; procedure WriteSeriesTitleLine; procedure WriteString(AString:string); procedure WritelnString(AString:string); procedure WriteStringLen(AString:string; ALength:integer); procedure WriteCommentString(AString:string); procedure WriteCommentBegin; procedure WriteCommentEnd; procedure WritelnCommentString(AString:string); procedure WriteON_OFF(AState:boolean); procedure Writeln; function LineComment:boolean; function NoLineComment:boolean; function Open:TFileStream; procedure Close; function Stream:TStream; procedure Assign(ADFF:tMsDataFileFormat); procedure WriteToRegistry(ARegstry:tRegistry); procedure ReadFromRegistry(ARegstry:tRegistry); procedure FlagSetState(AFlag:tMsDataFileFlag; AState:boolean); end; implementation USES Windows; constructor tMsDataFileFormat.Create; begin Inherited; prComment:=tStringList.Create; end; destructor tMsDataFileFormat.Destroy; begin Comment.Free; prStream.Free; Inherited; end; function tMsDataFileFormat.Open:TFileStream; resourcestring rcFile='Ôàéë: '; rcExists=' óæå ñóùåñòâóåò'; begin Close; if not (msdffOverride in Flags) and FileExists(FileName) then begin raise Exception.Create(rcFile+FileName+rcExists); end; Result:=TFileStream.Create(FileName, fmCreate or fmShareDenyWrite); prStream:=Result; end; procedure tMsDataFileFormat.Close; begin FreeAndNil(prStream); end; function tMsDataFileFormat.Stream:TStream; begin Result:=prStream; end; function tMsDataFileFormat.NoLineComment:boolean; begin Result:= not LineComment; end; function tMsDataFileFormat.LineComment:boolean; begin Result:= (Length(TextFile.CommentBegin)=0) and (Length(TextFile.CommentEnd)=0); end; procedure tMsDataFileFormat.WriteComment; var i:integer; //lc:boolean; begin if (Comment.Count>0) then begin WriteCommentBegin; if NoLineComment then begin WriteString(Comment.Text); // Writeln; end else begin for i:=0 to Pred(Comment.Count) do begin WriteString(TextFile.CommentLineBegin); WriteString(Comment[i]); Writeln; end; end; WriteCommentEnd; end; end; procedure tMsDataFileFormat.WriteString(AString:string); begin if (Length(AString)>0) then begin Stream.Write(AString[1],Length(AString)); end; end; procedure tMsDataFileFormat.WritelnString(AString:string); begin WriteString(AString); Writeln; end; procedure tMsDataFileFormat.WriteStringLen(AString:string; ALength:integer); begin if (Length(AString)0) then begin Stream.Write(AString[1],ALength); end; end; procedure tMsDataFileFormat.Assign(ADFF:tMsDataFileFormat); var i:integer; begin if ADFF=Self then Exit; Flags:=ADFF.Flags; FileName:=ADFF.FileName; Series:=ADFF.Series; MassMin:=ADFF.MassMin; MassMax:=ADFF.MassMax; TextFile.CommentBegin:=ADFF.TextFile.CommentBegin; TextFile.CommentEnd:=ADFF.TextFile.CommentEnd; TextFile.CommentLineBegin:=ADFF.TextFile.CommentLineBegin; { TextFile.CommentLineEnd:=ADFF.TextFile.CommentLineEnd;} TextFile.NumberSeparator:=ADFF.TextFile.NumberSeparator; TextFile.ColumnWidth:=ADFF.TextFile.ColumnWidth; TextFile.Format:=ADFF.TextFile.Format; TextFile.Precision:=ADFF.TextFile.Precision; TextFile.Digits:=ADFF.TextFile.Digits; prComment.Clear; for i:=0 to Pred(ADFF.prComment.Count) do begin prComment.Add(ADFF.prComment.Strings[i]); end; end; procedure tMsDataFileFormat.WriteToRegistry(ARegstry:tRegistry); begin ARegstry.WriteBinaryData('Flags',Flags,SizeOf(Flags)); ARegstry.WriteString('FileName',FileName); with TextFile do begin ARegstry.WriteString('CommentBegin',CommentBegin); ARegstry.WriteString('CommentEnd',CommentEnd); ARegstry.WriteString('CommentLineBegin',CommentLineBegin); // ARegstry.WriteString('CommentLineEnd',CommentLineEnd); ARegstry.WriteString('NumberSeparator',NumberSeparator); ARegstry.WriteBinaryData('Format',Format,SizeOf(Format)); ARegstry.WriteInteger('ColumnWidth',ColumnWidth); ARegstry.WriteInteger('Precision',Precision); ARegstry.WriteInteger('Digits',Digits); ARegstry.WriteString('CommentText',Comment.Text); end; ARegstry.WriteBinaryData('Series',Series,SizeOf(Series)); ARegstry.WriteFloat('MassMin',MassMin); ARegstry.WriteFloat('MassMax',MassMax); end; procedure tMsDataFileFormat.ReadFromRegistry(ARegstry:tRegistry); begin ARegstry.ReadBinaryData('Flags',Flags,SizeOf(Flags)); FileName:=ARegstry.ReadString('FileName'); with TextFile do begin CommentBegin:=ARegstry.ReadString('CommentBegin'); CommentEnd:=ARegstry.ReadString('CommentEnd'); CommentLineBegin:=ARegstry.ReadString('CommentLineBegin'); // CommentLineEnd:=ARegstry.ReadString('CommentLineEnd'); NumberSeparator:=ARegstry.ReadString('NumberSeparator'); ARegstry.ReadBinaryData('Format',Format,SizeOf(Format)); ColumnWidth:=ARegstry.ReadInteger('ColumnWidth'); Precision:=ARegstry.ReadInteger('Precision'); Digits:=ARegstry.ReadInteger('Digits'); Comment.Text:=ARegstry.ReadString('CommentText'); end; ARegstry.ReadBinaryData('Series',Series,SizeOf(Series)); MassMin:=ARegstry.ReadFloat('MassMin'); MassMax:=ARegstry.ReadFloat('MassMax'); end; function CenterStr(const AString:string; ALength:cardinal):string; var len,di,dj:cardinal; begin Result:=AString; len:=Length(Result); if len