I don't have much experience with OOP in AHKv2, but I was wondering if it's
possible to add an extra function to the File object in a script.
The function I had in mind would do the same thing as File.WriteLine( "some text" ),
but would also send "some text" to my debugger (using "OutputDebug").
Is that even possible?
Extending the File Object?
Re: Extending the File Object?
I don't believe that the File class is currently available globally from script. There's other classes that a similar strategy has to be used with I think. You basically have to use FileOpen to create an instance of a File object and then define a method on that object's base property. Something like this. You could obviously open any file first to create the method. I just chose StdOut.
Code: Select all
#Persistent
; Open a console window for this demonstration:
DllCall("AllocConsole")
f := FileOpen("*", "W")
f.base.DefineMethod("WriteLineDebug", (this, string) => !OutputDebug(string) && this.WriteLine(string))
f.close()
f := FileOpen("*", "W")
f.WriteLineDebug("This is a test")
f.close()
Re: Extending the File Object?
Thanks very much for this.