Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to convert a Delphi form (from file) to text and vice versa Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-Oct-02
Category
VCL-Forms
Language
Delphi 4.x
Views
21
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Misha Moellner

Convert your Delphi form from .dfm format to text and vice versa

Answer:

use this function to convert:

  Example (DFM->TXT): ConvertFormToText('unit1.dfm');
  Example (TXT->DFM): ConvertTextToForm('unit1.txt');

1   uses
2     SysUtils;
3   
4   function ConvertFormToText(SourceFileName: string): boolean;
5   var
6     InputStream, OutputStream: TFileStream;
7     DestFileName: string;
8   begin
9     result := true;
10  
11    { change the file extension to .txt }
12    DestFileName := ChangeFileExt(SourceFileName, '.txt');
13  
14    { Create a file stream for the specified file }
15    InputStream := TFileStream.Create(SourceFileName, fmOpenRead);
16    OutputStream := TFileStream.Create(DestFileName, fmCreate);
17  
18    { convert }
19    try
20      try
21        ObjectResourceToText(InputStream, OutputStream);
22      except
23        on EStreamError do
24          Result := False;
25      end
26    finally
27      { free memory }
28      InputStream.Free;
29      OutputStream.Free;
30    end;
31  end;
32  
33  function ConvertTextToForm(SourceFileName: string): boolean;
34  var
35    InputStream, OutputStream: TFileStream;
36    DestFileName: string;
37  begin
38    result := true;
39  
40    DestFileName := ChangeFileExt(SourceFileName, '.dfm');
41  
42    InputStream := TFileStream.Create(SourceFileName, fmOpenRead);
43    OutputStream := TFileStream.Create(DestFileName, fmCreate);
44  
45    try
46      try
47        ObjectTextToResource(InputStream, OutputStream);
48      except
49        on EStreamError do
50          result := false;
51      end
52    finally
53      InputStream.Free;
54      OutputStream.Free;
55    end;
56  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC