dfm窗体文件还原方法(100分)

  • 主题发起人 主题发起人 ajian320
  • 开始时间 开始时间
A

ajian320

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样实现把一个dfm文件(delphi自己生成的),用程序来实现动态还原呢?
 
给一点思路 仅供参考

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;


implementation

{$R *.DFM}

function ExtractDFM(ApplicationName, FormClassName: string): string;
var
AppHandle: THandle;
ResStream: TResourceStream;
ResultStream: TStringStream;
begin
Result := '';
AppHandle := LoadLibraryEx(PChar(ApplicationName), 0, LOAD_LIBRARY_AS_DATAFILE);
if AppHandle = 0 then
raise Exception.Create('Could not load application');
ResStream := nil;
ResultStream := nil;
try
ResStream := TResourceStream.Create(AppHandle, FormClassName, RT_RCDATA);
ResultStream := TStringStream.Create('');
ObjectBinaryToText(ResStream, ResultStream);
Result := ResultStream.DataString;
finally
ResultStream.Free;
ResStream.Free;
FreeLibrary(AppHandle);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(ExtractDFM('D:/aaa.exe', 'TForm1'));
end;

end.
 
后退
顶部