Skip to content
Snippets Groups Projects
Commit b60cc75b authored by deuce's avatar deuce
Browse files

Fix up RecordFile and add a new RecordFileRecord class.

parent 74417542
Branches
Tags
No related merge requests found
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment