[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Saving runtime created form.

Is it possible to save a form to a blob stream or file that was created during runtime?

I have tried saving the form using WriteComponent but I get an error when trying to read it back in. (Class TEdit not found).

I would like the user to be able to create a form during runtime and save it then allow them to load it back in later.
0
CalvinDay
Asked:
CalvinDay
  • 3
1 Solution
 
edeyCommented:
Did you remember to include stdctrls in the unit you used to load the component?


GL
Mike
0
 
CalvinDayAuthor Commented:
Yes it was already there.
0
 
CalvinDayAuthor Commented:
Isn't this supposed to work?

procedure TForm1.Button2Click(Sender: TObject);
var
  fs:TFileStream;
begin
  fs:=TFileStream.Create('c:\test.dfm', fmCreate);
  fs.WriteComponent(Form1);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  fs:TFileStream;
  Form:TForm;
begin
  fs:=TFileStream.Create('c:\test.dfm', fmOpenRead);
  Form:=fs.ReadComponent(nil) as TForm;
  Form.Show;
end;


This gives me the error:
Class TForm1 not found.
0
 
rwilson032697Commented:
Which one? The read or the write?

Classes which are read/written to streams like this need to be registered, like this:

registerClasses([TEdit, T...]);

Cheers,

Raymond.
0
 
CalvinDayAuthor Commented:
Excellent Raymond!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now