Archived

This topic is now archived and is closed to further replies.

TheSisko

class......

Recommended Posts

Ok, in the first unit, I declared open as follows:
  TOpen = class
    procedure OpenIcon;
    procedure OpenPicture;
    procedure OpenSound;
    procedure OpenText;
    procedure OpenVideo;
    procedure SaveText;
    procedure SaveIcon;
  end;
 
now, in the 2nd unit, I put this in a procedure:
Case RadioGroup1.ItemIndex of
0: TForm1.TOpen.OpenIcon;
1: TForm1.TOpen.OpenPicture;
2: TForm1.TOpen.OpenSound;
3: TForm1.TOpen.OpenText;
4: TForm1.TOpen.OpenVideo;
 
I know this is totally wrong. What should TForm1.TOpen.OpenIcon; be changed to???

Share this post


Link to post
Share on other sites
You must create an object of your new class.
On the first unit, create a var of this object (under the Form1:TForm1)

NewOpen: TOpen;

On the OnCreate of the form:

NewOpen := TOpen.Create;

And on the second unit, you dont need use TForm1. because our object is not a property of the form. But you need put the unit1 on the uses, but the uses just after the implementation declaration, as follows:

implementation

uses Unit1; // (or the filename of your unit1)

Finally to use the new object:

Case RadioGroup1.ItemIndex of
0: NewOpen.OpenIcon;
1: NewOpen.OpenPicture;
2: NewOpen.OpenSound;
3: NewOpen.OpenText;
4: NewOpen.OpenVideo;
end;

There are some remarks here. You can only use the NewOpen object on unit 2, if its declared on unit 1 before implementantion section (on interface), because just symbols on interface are exported to others units.

I think this solves your problem.

Share this post


Link to post
Share on other sites