Calling one class from another

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
djvj11
Posts: 15
Joined: 21 Jun 2014, 01:30

Calling one class from another

24 Feb 2016, 01:29

I need to create a File object when I create the Process object but how come the msgbox in File class never shows up?

Code: Select all

primaryExe := new Process(emuPath . "\" . executable)
ExitApp

class File
{
	__New(file)
	{
		SplitPath, file, file, path, ext, fileNE, drive
		this.FileDrive := drive
		this.FileName := file
		this.FileNameNoExt := fileNE
		this.FilePath := path
		this.FileExt := ext
		msgbox % A_ThisFunc . ": " . this.FileName
	}

}

class Process
{
	__New(file)
	{
		this.processFile := new File(file)
		msgbox % A_ThisFunc . ": " . this.processFile.FileName
	}
}
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Calling one class from another

24 Feb 2016, 02:02

It's a variable name conflict. class File creates a super-global variable named "File" which holds a reference to the class object. this.processFile := new File(file) -> File here refers to the function parameter not the class object. Rename the function parameter to something like f or rename the class to something like CFile and your code should work. Btw, AutoHotkey is not case-sensitive when it comes to variable/function names.
djvj11
Posts: 15
Joined: 21 Jun 2014, 01:30

Re: Calling one class from another

24 Feb 2016, 03:07

You were right, that was it! Thank you.

That can be a nightmare to troubleshoot w/o a loadtime error in large scripts.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 335 guests