폼을 stream을 사용하여 TEXT로 저장을했읍니다..
저장한 TEXT파일로 폼을 다시 만들 수 없나?...
readcomponent를 사용하였으나 에러만 나고 안되네요?
[저장]
<!--CodeS-->
var
Stream2: TFileStream;
Stream1: TMemoryStream;
mFile : string;
begin
try
Stream1 := TMemoryStream.Create;
mFile := ChangeFileExt(ExtractFilePath(ParamStr(0))+'map\test', '.dat');
Stream2 := TFileStream.Create(mFile,fmCreate);
try
Stream1.WriteComponent(Application.MainForm.ActiveMDIChild);
Stream1.position := 0;
ObjectBinaryToText(Stream1, Stream2);
finally
Stream1.Free;
Stream2.Free;
end;
except
on e : Exception do showmessage(e.Message);
end;
end;
<!--CodeE-->
아래 코드를 참고하세요..
// ObjectResourceToText : converts the binary representation of an object
// resource into more readily understandable text.
// ObjectTextToResource : converts a symbolic text representation of an object
// into the binary representation into Delphi's internal binary representation.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TDFMorTXT = (ConvertToForm, ConvertToText);
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function ConvertFormOrText(FileToConvertFrom: string;
ConversionType: TDFMorTXT): boolean;
var
InputStream, OutputStream: TFileStream;
FileToConvertTo: string;
begin
Result := True;
FileToConvertTo := FileToConvertFrom;
case ConversionType of
ConvertToForm: {TXT -> DFM}
begin
FileToConvertFrom := SysUtils.ChangeFileExt(FileToConvertFrom, '.TXT');
FileToConvertTo := SysUtils.ChangeFileExt(FileToConvertFrom, '.DFM');
end;
ConvertToText: {DFM -> TXT}
begin
FileToConvertFrom := SysUtils.ChangeFileExt(FileToConvertFrom, '.DFM');
FileToConvertTo := SysUtils.ChangeFileExt(FileToConvertFrom, '.TXT');
end;
end;
try
try
InputStream := TFileStream.Create(FileToConvertFrom, fmOpenRead); {읽기용}
OutputStream := TFileStream.Create(FileToConvertTo, fmCreate); {쓰기용}
case ConversionType of
ConvertToForm: ObjectTextToResource(InputStream, OutputStream);
ConvertToText: ObjectResourceToText(InputStream, OutputStream);
end;
except
on EStreamError do
Result := False;
end;
finally
InputStream.Free;
OutputStream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
if UpperCase(ExtractFileExt(OpenDialog1.FileName)) = '.DFM' then
ConvertFormOrText(OpenDialog1.FileName, ConvertToText) {DFM -> TXT}
else if UpperCase(ExtractFileExt(OpenDialog1.FileName)) = '.TXT' then
ConvertFormOrText(OpenDialog1.FileName, ConvertToForm); {TXT -> DFM}
end;
end;
end.