Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reach objects on Form1 from Form2? 1

Status
Not open for further replies.

MrDoch

Programmer
Aug 6, 2004
6
DE
Hello,

How can I write "Form1.Edit1.SetFocus;" from Form2
when Form2 (Unit2) is in the Uses List of Form1 (Unit1)?

If I include Unit1 in the Uses List of Unit2 then I get an error because Unit1 and Unit2 references eachother!

Thanks in advance!
 
Have you tried putting Unit1 in the uses list in the implementation section of Unit2 as opposed to the interface section?


Hope this helps.

[vampire][bat]
 
That works, thanks!

Can you explain the difference between the two implementation sections?
 
This has been copied from Delphi 7 help and explains things better than I could. There are other references within the help file but I felt that these three were the most relevant.

Delphi Help files said:
The interface section of a unit begins with the reserved word interface and continues until the beginning of the implementation section. The interface section declares constants, types, variables, procedures, and functions that are available to clients--that is, to other units or programs that wish to use elements from this interface section. These entities are called public because a client can access them as if they were declared in the client itself.

The interface declaration of a procedure or function includes only the routine's heading. The block of the procedure or function follows in the implementation section. Thus procedure and function declarations in the interface section work like forward declarations, although the forward directive isn't used.

The interface declaration for a class must include declarations for all class members.

The interface section can include its own uses clause, which must appear immediately after the word interface. For information about the uses clause, see Unit references and the uses clause.


=======================


The implementation section of a unit begins with the reserved word implementation and continues until the beginning of the initialization section or, if there is no initialization section, until the end of the unit. The implementation section defines procedures and functions that are declared in the interface section. Within the implementation section, these procedures and functions may be defined and called in any order. You can omit parameter lists from public procedure and function headings when you define them in the implementation section; but if you include a parameter list, it must match the declaration in the interface section exactly.

In addition to definitions of public procedures and functions, the implementation section can declare constants, types (including classes), variables, procedures, and functions that are private to the unit--that is, inaccessible to clients.

The implementation section can include its own uses clause, which must appear immediately after the word implementation. For information about the uses clause, see Unit references and the uses clause.


========================


When units reference each other directly or indirectly, the units are said to be mutually dependent. Mutual dependencies are allowed as long as there are no circular paths connecting the uses clause of one interface section to the uses clause of another. In other words, starting from the interface section of a unit, it must never be possible to return to that unit by following references through interface sections of other units. For a pattern of mutual dependencies to be valid, each circular reference path must lead through the uses clause of at least one implementation section.

In the simplest case of two mutually dependent units, this means that the units cannot list each other in their interface uses clauses. So the following example leads to a compilation error:

unit Unit1;
interface
uses Unit2;
...
unit Unit2;
interface
uses Unit1;
...

However, the two units can legally reference each other if one of the references is moved to the implementation section:

unit Unit1;
interface
uses Unit2;
...
unit Unit2;
interface
...
implementation
uses Unit1;
...

To reduce the chance of circular references, it's a good idea to list units in the implementation uses clause whenever possible. Only when identifiers from another unit are used in the interface section is it necessary to list that unit in the interface uses clause.


=================================


Hope this helps.

[vampire][bat]
 
Both Delphi 3 and 5 would spot your reference to the form and ask if you wanted to add the unit to the uses clause on the first compile after it's entry.
Or am I thinking of something else ?

My Feeblegirl.com Forum boards for mmorpgs, sport, fun, politics...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top