In the: DFM files and XML files, the DFM files used must be a text format. If it is a binary format, the processing will be wrong.
But how to determine DFM is a binary file in processing, and then the binary file is converted to a text format. ---
When the DFM file binary format, its file will add a file header, where the first 3 bytes identifies it as binary, these three bytes are: $ FF, $ 0A, $ 00. Because these three bytes in the text The type of file is impossible, so it can be judged that these 3 bytes can be.
Function Isbindfm (const adfmfilename: string): boolean;
VAR
Mbinstream: TMemoryStream;
MBuff: array [0..2] of byte;
Begin
Mbinstream: = TMEMORYSTREAM.CREATE;
Try
Mbinstream.LoadFromFile (AdfmFileName);
Mbinstream.read (MBUFF, 3);
// The first three bytes: $ FF, $ 0A, $ 00
IF (MBuff [0] = $ ff) and (mbuff [1] = $ 0a) and (mbuff [2] = $ 00) THEN
Result: = TRUE
Else
Result: = FALSE;
Finally
Mbinstream.free;
END;
END;
After judging, it is easy to turn the binary to a text format. Delphi provides the ObjectResourceTotExT function. Wait as follows:
Procedure Dfmbin2TXT (AdfmFileName: String);
VAR
InfileStream: TMemoryStream;
Outfilestream: TfileStream;
Begin
InfileStream: = TMEMORYSTREAM.CREATE
InfileStream.LoadFromFile (AdfmFileName);
Try
OutfileStream: = TfileStream.create (AdfmFileName, Fmcreate);
Try
Try
InfileStream.seek (0, Sofrombeginning);
ObjectResourceTotext (InfileStream, OutfileStream);
Except
Raise Exception.create ('this DFM IS BIN, Error On Trans Bin To Txt.');
END;
Finally
Outfilestream.free;
END;
Finally
InfileStream.free;
END;
END;
At this point, I'm big!