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
candoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.