Procedure ObjBinToTxt(Input, Output: tstream);
Begin
Input.Position := 0;
Input.ReadResHeader;
ObjectBinaryToText(Input, Output);
End;
Procedure ObjTxtToBin(Input, Output: tstream);
Var
Len: Byte;
Tmp: LongInt;
MemSize: LongInt;
Header: Array[0..79] Of char;
MS: TMemoryStream;
Begin
MS := TMemoryStream.Create;
Input.Position := 0;
objecttexttobinary(Input, MS);
MemSize := MS.Size;
FillChar(Header, SizeOf(Header), 0);
MS.Position := SizeOf(LongInt);
MS.Read(Len, 1);
If Len And $F0 = $F0 Then
Begin
If ffChildPos In TFilerFlags(Len And $F0) Then
Begin
MS.Read(Len, 1);
Case TValueType(Len) Of
vaInt8: Len := 1;
vaInt16: Len := 2;
vaInt32: Len := 4;
End;
MS.Read(Tmp, Len);
End;
MS.Read(Len, 1);
End;
MS.Read(Header[3], Len);
StrUpper(@Header[3]);
Byte((@Header[0])^) := $FF;
word((@Header[1])^) := 10;
word((@Header[Len + 4])^) := $1030;
LongInt((@Header[Len + 6])^) := MemSize;
Output.Write(Header, Len + 10);
Output.Write(MS.memory^, MemSize);
MS.Free;
End;
Function DfmToText(Const DfmFile, TxtFile: String): Boolean;
Var
FS: tstream;
MS: tstream;
FileHead: SmallInt;
Begin
Result := False;
If Not FileExists(DfmFile) Then Exit;
If Length(TxtFile) < 4 then Exit;
FS := TFileStream.Create(DfmFile, fmOpenRead);
MS := TMemoryStream.Create;
FS.Position := 0;
FS.Read(FileHead, 2);
If FileHead = $0AFF Then
ObjBinToTxt(FS, MS)
Else
(MS As TMemoryStream).LoadFromStream(FS);
MS.Position := 0;
(MS As TMemoryStream).SaveToFile(TxtFile);
Result := True;
MS.Free;
FS.Free;
End;
Function TxtToDfm(Const TxtFile, DfmFile: String): Boolean;
Var
FS: tstream;
MS: tstream;
FileHead: SmallInt;
Begin
Result := False;
If Not FileExists(TxtFile) Then Exit;
If Length(TxtFile) < 4 then Exit;
FS := TFileStream.Create(TxtFile, fmOpenRead);
MS := TMemoryStream.Create;
FS.Position := 0;
FS.Read(FileHead, 2);
If FileHead <> $0AFF Then
ObjTxtToBin(FS, MS)
Else
(MS As TMemoryStream).LoadFromStream(FS);
MS.Position := 0;
(MS As TMemoryStream).SaveToFile(DfmFile);
Result := True;
MS.Free;
FS.Free;
End;