You will have to be carefull do to corrupt the form because delphi sorts a
lot of the problems out by removing properites that no longer exist. I did a
program like this once and I will see if I can find the source.

To Load the form into MyStringList

            FFileStream:= TFileStream.Create('C:\Form1.dfm', fmOpenRead);
            try
               instream:= TMemoryStream.Create;
               try
                  ObjectResourceToText(FFileStream, instream);
                  instream.Position:= 0;
                  MyStringList.LoadFromStream(instream);
               finally
                  instream.free;
               end;
         finally
            FFileStream.Free;
         end;

To Save the form


      FFileStream:= TFileStream.Create('C:\Form1.dfm', fmCreate);
      try
            outstream:= TMemoryStream.Create;
            try
               MyStringList.SaveToStream(outstream);
               outstream.Position:= 0;
               ObjectTextToResource(outstream,FFileStream);
            finally
               instream.free;
            end;
       finally
            FFileStream.Free;
       end;



-----Original Message-----
From: Steven Wild <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Date: Friday, 30 April 1999 07:16
Subject: [DUG]: Reading dfm files


I have a need to be able to read in a dfm, alter it,  and write
it back to the  dfm file from within another Delphi app.

Does anyone have some code that will read a dfm into ledgeable
form...  into a TstringList would be very helpful ...  and then
write the altered one back out to file.

Why???  Well I want to be able to test and set a value on about 1000
instances of a small group of components where they are used.  Rather
than open all forms in the project and manually look for each
possible instance of the components, I want to just be able
to automate the process.  I just thought that automating processes is
what we are all about so why not do it to dfms as well!

Steven Wild
Wild Software Ltd
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to