From b60cc75b9e713ea870542ff4f47180179f534c1f Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Sun, 2 Feb 2014 06:19:26 +0000
Subject: [PATCH] Fix up RecordFile and add a new RecordFileRecord class.

---
 exec/load/recordfile.js | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/exec/load/recordfile.js b/exec/load/recordfile.js
index e002e15e6b..b34ede5e65 100644
--- a/exec/load/recordfile.js
+++ b/exec/load/recordfile.js
@@ -42,15 +42,22 @@ function RecordFile(filename, definition)
 	this.__defineGetter__("length", function() {return parseInt(this.file.length/this.RecordLength);});
 }
 
-RecordFile.prototype.ReInit = function()
+function RecordFileRecord(parent, num)
+{
+	this.parent=parent;
+	this.Record=num;
+}
+
+RecordFileRecord.prototype.ReLoad = function(num)
 {
 	var i;
 
+	this.parent.file.position=(this.Record)*this.parent.RecordLength;
 	for(i=0; i<this.parent.fields.length; i++)
-		this[this.parent.fields[i].prop]=eval(this.parent.fields[i].def.toSource());
+		this[this.parent.fields[i].prop]=this.parent.ReadField(this.parent.fields[i].type);
 }
 
-RecordFile.prototype.Put = function()
+RecordFileRecord.prototype.Put = function()
 {
 	var i;
 
@@ -59,20 +66,18 @@ RecordFile.prototype.Put = function()
 		this.parent.WriteField(this[this.parent.fields[i].prop], this.parent.fields[i].type, this.parent.fields[i].def);
 }
 
-RecordFile.prototype.ReLoad = function(num)
+RecordFileRecord.prototype.ReInit = function()
 {
 	var i;
 
-	this.parent.file.position=(this.Record)*this.parent.RecordLength;
 	for(i=0; i<this.parent.fields.length; i++)
-		this[this.parent.fields[i].prop]=this.parent.ReadField(this.parent.fields[i].type);
+		this[this.parent.fields[i].prop]=eval(this.parent.fields[i].def.toSource());
 }
 
 RecordFile.prototype.Get = function(num)
 {
 	var rec=0;
 	var i;
-	var ret=new Object();
 
 	if(num==undefined || num < 0 || parseInt(num)!=num)
 		return(null);
@@ -81,12 +86,7 @@ RecordFile.prototype.Get = function(num)
 	if(num>=this.length)
 		return(null);
 
-	ret.parent=this;
-	ret.Put=RecordFileRecord_Put;
-	ret.ReLoad=RecordFileRecord_ReLoad;
-	ret.ReInit=RecordFileRecord_ReInit;
-
-	ret.Record=num;
+	var ret = new RecordFileRecord(this, num);
 
 	this.file.position=ret.Record * this.RecordLength;
 	for(i=0; i<this.fields.length; i++)
@@ -98,16 +98,11 @@ RecordFile.prototype.Get = function(num)
 RecordFile.prototype.New = function()
 {
 	var i;
-	var ret=new Object();
 
 	for(i=0; i<this.fields.length; i++)
 		ret[this.fields[i].prop]=eval(this.fields[i].def.toSource());
 
-	ret.parent=this;
-	ret.Put=RecordFileRecord_Put;
-	ret.ReLoad=RecordFileRecord_ReLoad;
-	ret.ReInit=RecordFileRecord_ReInit;
-	ret.Record=this.length;
+	var ret=new RecordFileRecord(this, this.length);
 	ret.Put();
 	return(ret);
 }
-- 
GitLab