Re: Multiple Forms - Cannot access array


[ Related Articles and Replies ] [ DelphiLand Discussion Forum ]

Posted by webmaster Guido on January 18, 2003 at 15:27:38:

In Reply to: Multiple Forms - Cannot access array posted by Mike Baily on January 17, 2003 at 17:56:03:

: I am using multiple forms for the first time. I have created an array in unit1.pas I have created a new form. From form2 if I enter form1.
: a dialog appears with all the properties of the form but I want to access the array I have created but it is not listed.

: How do I access the array that I created in 1 form and allow the user to amend it from another form?

----------

1. Declare your array in the "interface" section of Form1, right under the line that says "public" (instead of declaring the array under "var"). That way, it becomes a "field" of Form1 that can be accessed from other units. Example:

public
Array1: array[1..100] of integer;

2. In Form2, add a line in the implementation section, right under the line that says "implementation":

uses unit1;

Note: "unit1" is the unit-file (the *.pas file) of Form1. So, if that file is not named "unit1.pas" but for example "main.pas", this becomes:
uses main.pas;

3. In order to access the array from Form2, put "Form1." in front of it, for example:

Form1.Array1[10] := 1;


Related Articles and Replies:


[ DelphiLand Discussion Forum ]