Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can see that the CLW file contains a declaration of a LONG variable, declared outside the class but inside the class's source module. The one method in the class returns the address of this variable. 

Now hereHere's a small program to prove that SomeClassModuleData is the same in all instances of DemoClass:

...

You can see why I had a problem with multiple instances of AnyAsciiFileClass, What I needed was one file structure for each instance of the class. Only it isn't possible to declare a file layout inside a class. Files have to be declared at compile time; you can't create the on the fly at runtime (at least not without the Dynamic File Driver or DynaLib). 

...

My first thought was to write this pool management code as a separate class. My second thought was that the code would be pretty simple, so I might as well just do it with a few procedures and a queue declared in the class source module. And my third thought, after about five minutes of coding, was that it would probably be best after all to write the code as a separate class, which is what I did.

Sometimes when I create a new class the name of the class is obvious; other times I agonize over my choice, often changing it later. I'm still mulling over this one. In any case, I decided to call it DCL_System_Pool, although it's not really an object pool, more of a reference number pool. But it can server as a basis for more involved pool implementations, so for now DCL_System_Pool it is. If you're reading this years later and you don't see a class by that name in the DCL, keep looking. It's probably there somewhere. 

...

The logic is pretty easy to follow; when you get a pool element it's marked as in use; when you're done with it and release it the flag is cleared. There's also some support for customizing error handling. And to To make the class thread safe I've added a critical section.

Clearly even if this is the only place I ever use the class, having it in its own INC and CLW makes the class easier to work with , and more visible within the DCL library

Inside DCL_System_IO_AsciiFileManager I added five file layouts:

...

Code Block
DCL_System_IO_AsciiFile.Construct        PROCEDURE()
    CODE
	self.Errors &= new DCL_System_ErrorManager
	self.PoolItemNumber = AsciiFilePool.GetItemNumber()
	execute self.PoolItemNumber
		self.Init(AsciiFile1,AsciiFile1:Record,AsciiFileName1)
		self.Init(AsciiFile2,AsciiFile2:Record,AsciiFileName2)
		self.Init(AsciiFile3,AsciiFile3:Record,AsciiFileName3)
		self.Init(AsciiFile4,AsciiFile4:Record,AsciiFileName4)
		self.Init(AsciiFile5,AsciiFile5:Record,AsciiFileName5)
	else
		stop('Unable to initialize the ASCIIFile instance - if you continue the program will probably crash')
	end
	
DCL_System_IO_AsciiFile.Destruct         PROCEDURE()
	CODE
    SELF.CloseFile()
	AsciiFilePool.ReleaseItemNumber(self.PoolItemNumber)
	dispose(self.Errors)


I've updated the GitHub repository with these changes. If you previously used the ASCIIFileManager approach then you'll need to make two simple changes:

...