Any example code.... from unit1 try:
DataModule1.TFOO.tag:= 1
I'm pretty sure I tried that, but it didn't work....
Are you trying to use the main form objects from the datamodule unit?
No, the reverse; I'm trying to use components I've placed in the datamodule unit from the main form (Unit1).
Then you'd need to add the main form unit to a uses section of the datamodule unit, then do similar to the above example but in reverse - Form1.something... within Unit2.
That's what I tried to do, but in reverse. For example, I make a Form that has a Button. I make a new DataModule and put a TrayIcon in it. I put 'Unit2' in the 'Uses' section of Unit1, and put this code in Unit1 to make the TrayIcon show when I click the Button.
procedure TForm1.Button1Click(Sender: TObject);
begin
TrayIcon1.Show;
end;
I get this error:
unit1.pas(34,12) Error: Identifier not found "TrayIcon1"
**A FEW BRAINCYCLES LATER... **
procedure TForm1.Button1Click(Sender: TObject);
begin
DataModule1.TrayIcon1.Show;
end;
OK, now I get it.
TurboRascal put it right in my face, but I didn't see it.
Just remember you cannot add Unit1 to the interface uses section of Unit2 because that would create a circular reference since you already have Unit2 in the uses section of Unit1. You must do that in the implementation section.
Yes, common sense prevents me from trying that.
So, now I'm wondering now about what would be proper programming practice in this case. Should I use the DataModule as my main Unit and put all the code for the Form in there? Or is using a DataModule as a secondary container (per my example) better?. I realize this is only necessary as projects grow big enough to make modularizing a better way to handle the code, but I'm learning what I can while I'm still a beginner.