• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

draw form

Hello,

How can I create a picture of a form from the source, like the ide does? I need to make it work for not only standard components, but for third party components also.

Thanks in advance.
Cando
0
cando
Asked:
cando
  • 4
  • 2
1 Solution
 
rwilson032697Commented:
You can do it like this:

Var
  Form : TForm;
  Stream : TFileStream;
 
begin
  try
    Stream := TFileStream.Create('MyFoem.dfm', fmRead);
    try
      Stream.ReadComponentRes(Form);
    finally
      Stream.Free;    
    end;  
  except    
    on EFOpenError do
     {nothing};  
    end;
  TheForm.Show;
end;

For all components in the form you must do this:

RegisterComponents([TComponent1, TComponent2...]);

Cheers,

Raymond.
0
 
candoAuthor Commented:
Hello,

I tired you code and it doesn't seem to work. I dont understand what you mean by the register component part either.

Thanks,
Cando
0
 
rwilson032697Commented:
I'm sorry, the code I posted wont work. Unfortunately to do this 'properly' requires some changes to the VCL (and I suspect you do not want to do this) and substantially more code.

Have a look at:

ReadComponentResFile and WriteComponentResFile (Defined in classes.pas).

These will save and load a form to and from a file. Is this what you want?

I also made a mistake with registercomponents - it should be registerclasses. This registers classes with the streaming system for read and writing to forms.

Let me know...

Cheers,

Raymond.
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
rwilson032697Commented:
Here's an example using ReadComponentResFile :

var
  Form : TForm;

....

  Form := TForm.Create(Application);
  ReadComponentResFile('TheForm.dfm', Form);
  Form.Show;


There is one catch (the same one in a round about way that skittled the first approach), which is if there are any event handlers etc used by components on the form then the form will not load.

Cheers,

Raymond.
0
 
candoAuthor Commented:
rwilson,

this code only works if there are no controls on the form? I need to draw the form with its controls and I need to draw the third pary controls also, with the source of course. Can you help me?

cando
0
 
rwilson032697Commented:
>this code only works if there are no controls on the form?  

Sorry, is this a statement or a question?

What I am saying is that if, for instance, you have a button on the form with an onclick handler to a method in the form unit, then the form won't load because the streaming code can't locate the handler in the code (because it won't be there).

Cheers,

Raymond.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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