Methods in other than Program, *.pas files

My main pascal code is in Program.pas, but I have several other *.pas files with data & some utility methods. They all work fine. Program.pas is large & to make things easier I moved many methods to another *.pas. All calls to methods in Program.pas result in errors - I seem to recall the compiler saying it does not recognize the Program.pas methods. Why? Perhaps preceding such calls with “Program.” as in Program.methodname would work?
Thanks, --tex

Do you have the same namespace (or legacy unit) name in all files?

Yes, the 1st line of all *.pas files in the project have the same namespace line. The methods in Program.pas can call all methods in all *pas files & all *.pas methods in all files can access all global constants & vars in all other *.pas files. Program.pas has no Global constants nor vars as I like to keep such separate in in the *.pas files related to the data.

Previously the only methods in the non-Program.pas files were self-contained utilities returning some (usually a calculation) result to the Program.pas calling methods.

Recently as Program.pas became large I removed many related (mostly initialization) methods & put them in a separate *.pas file, but some referenced Program.pas methods, e.g. initialization methods to create HTML elements with events (onClick, onmouseover, onmouseout, etc) = new WebAssemblyDelegate( (a) → ROOut(1)), where ROOut is in Program.pas. The compiler does not recognize the method ROOut in Program.pas, but is fine if the initialization methods are also in Program.pas.

Maybe it only fails with "new WebAssemblyDelegate… Program.pas methods)? I did not track that.

Can I see this project to have a look? This should work fine, bit its rather hard to diagnose without seeing exactly what is going on…


Thanks for your offer of help but I’m under pressure of upcoming targets & the project is large. I was hoping it was a top-of-your head problem, like putting in a “uses” statement.

I’ve solved the problem by putting all methods that call Program.pas methods back into Program.pas. Assuming you are correct & methods in other files should be able to call Program.pas methods, someday I’ll try to see if the problem is limited to "new WebAssemblyDelegate… Program.pas methods) as such is different than normal method calls (involving WebAssemblyDelegats). I’ll let you guys know what I find when I get the time.

My recollection, which may be wrong, of RAD Studio Delphi is that when calling Procedures/Functions in other *.pas files (call 'em subfiles for now) I had to put the subfile names in a “uses” statement at the top & when a subfile Procedure called a main Procedure I had to put the main.pas name in a uses statement, but not the top one, another uses statement just before the Procedures section, i.e. there was something special about subfile Procedures calling back main Procedures. I believe I could avoid this by prefixing the Procedure with the name of the file the Procedure was in, i.e. OtherFile.DoOtherStuff4Me; --tex

If they are all in the same namespace, you shoudln’t need a uses clause.


Yeah, that’s because Delphi doesn’t do namespaces; each unit is its own scope and needs to be used, much like #incliuding a C header. Oxygene does not have that limitation.