views:

118

answers:

5

i made a simple form designer in delphi, drag and drop a button on the form and it draws it, but the thing is i cant save/load this project since i dunno how to, is there anyway that i could be abel to save it to .rc file and load it from there?

+1  A: 

Delphi stores form layout in *.dfm file. You can use it's structure to save your projects. File is textual and readable by humans. It is not hard to parse file like that rading one line by one. If you need more help, ask for it.

Ljubomir Đokić
its not delphi thing, its a total project independant from delphi, im making a form designer of my owen, to be abel to save form as .rc file and use it in any C++ or C project or even ASMdelphi got nothing to do with it, just the programming language im using
killercode
I realised that you are building form designer for something else. I suggest that you save your forms in file that have structure like dephis *.dfm file. You use that file in your application to save/load forms. While saving you can save in both *.dfm and any other filetype.
Ljubomir Đokić
A: 

If you just want to save the form you designed in your designer, use something like TFileStream to create the RC file when the user saves. You might be better off with your own file format for your forms, with the option to export as an RC file, as RC files arent really meant to useful for storing any design time info you may need.

GrandmasterB
the problem is that i dunno how to do that, what should i do to get the newly created controls? and their sizes? i have no problem with saving the data to file, but the problem is how to generate this data
killercode
The actual problem is your question does not provide nearly enough information about how you are making this designer, how you are keeping track of the info about the controls you are creating, etc. For example, it sounds like you are just creating controls and putting them on a form without any means of keeping track of what you are creating. That doesnt sound very effective. What you want to do is break your questions down so that they are much more specific, and then we can give you better informed answers.
GrandmasterB
+1  A: 

The VCL contains methods for using its builtin DFM support. There is a sample in the Delphi 2009 documentation for ObjectBinaryToText; I guess this works for D7 too. And IIRC there already was a code fragment for ComponentToString in the D5 help - search for ObjectBinaryToText.

Ulrich Gerhardt
There's the symmetric function as well - ObjectTextToBinary. Both have a full functioning conversion sample in D7 help.
Fabricio Araujo
+1  A: 

That depends how you programmed your form designer. In forms created in Delphi's designer all components (and subcomponents) are referenced from TForm.Components array property. All controls are also referenced in TForm.Controls array property (if you remove an container control, all it's subcontrols are destroyed too).

If you have followed that pattern, all you have to do is monitor additions to the TForm.Components array (maybe using an overriden TForm.Notification method) and using this data to build your persistent form's file.

Fabricio Araujo
A: 

You can use something like delphi .DFM. Counting all objects and then read their attributes and write them into a file. Example Code:

For i:0 To Form1.ComponentsCount-1 Do Begin
  // Read Component Attributes And Write Them In Your Format
End;
Armin
ty, now i know exactly what to do :)
killercode