Re: Newbie Needs Help with Forms




"PcolaBob" <globalteambuilder@xxxxxxxxx> wrote in message
news:1151628826.675599.21850@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hey Everybody. I just joined the group. I am trying to learn Delphi
6. I am coming from a VB background, and things which I think should be
so simple, seem to be so difficult in Delphi. For example, how do you
navigate from one form to another. If I have Form1 and Form2, and I
want to put a button on Form1 that displays Form2, what code does it
take. In VB if the form was in the project, all I had to do was to
call the Form's SHOW method and that would load it into memory and
display it. I could call it's HIDE method to continue to hold it in
memory but not be displayed, or I could use the Unload statement to
remove it from memory. I want to have the button on Form1 that displays
Form2 and hides Form1. Then I want a Close button on Form2 that
unloads Form2 and displays Form1 again. Can someone please give me the
steps to do this in Delphi. My Unit1.pas doesn't seem to be able to
see Unit2.pas. It's very confusing.

Its important to realize that as far as Delphi is concerned forms are
objects. They are declared and can be manipulated like any other object in
a project. This isn't readily apparent because the Delphi IDE manages code
that automatically declares form variables and creates form instances for
those variables. But this is behavior that can be controlled by the
programmer.

In each unit in which a form is declared one will find a form variable
declared in the Interface section. In the main project file one will find a
series of statements that create the form objects. These are termed
automatically created forms. In Project | Options, Forms tab, one can
control which, if any, forms should be automatically created. In large
projects its not uncommon to manually manage the creation and destruction
of form instances. One can also do this for property *** type and other
multiple instance forms.

As Maarten pointed out Delphi has different visibility rules from VB. They
tend to be stricter. A unit can not see anything declared in a different
unit unless it is included in a Uses clause of the referencing unit. There
are up to two uses clauses and visibility of a used unit follows from the
point of its "use". You may want to check out the Delphi (Object Pascal)
Reference section of the help, particularly the entries that deal with
identifier scope and visibility.


.


Quantcast