killercode
killercode

Reputation: 1706

Form Designer Save and Load

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?

Upvotes: 2

Views: 2134

Answers (5)

Armin Taghavizad
Armin Taghavizad

Reputation: 1685

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;

Upvotes: 1

Fabricio Araujo
Fabricio Araujo

Reputation: 3820

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.

Upvotes: 3

Uli Gerhardt
Uli Gerhardt

Reputation: 13991

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.

Upvotes: 2

GrandmasterB
GrandmasterB

Reputation: 3445

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.

Upvotes: 0

Ljubomir Đokić
Ljubomir Đokić

Reputation: 426

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.

Upvotes: 1

Related Questions