default methods

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

13-Apr-12 07:24
I am trying to impliment code to replace the MS Tabular data control.
How do I go about creating a Fields collection object
that has a default method of Item(idx)
ie.
myrs.Fields.Item(4).name
is the same as
myrs.Fields(4).name

--
rshep2
14-Apr-12 12:20
In what language??

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
15-Apr-12 02:15
sry javascript

--
rshep2
18-Apr-12 02:48
Something like...



function myFields(idx)
{
this.Count = 0;

this.curfld = -1;
this.fld_arr = [];
this.fldname_idx_arr = [];

this.item = function(idx) {
return this.fld_arr[idx];
}

this.append = function(fldName, fldValue) {
if ( typeof(this.fldname_idx_arr[fldName]) == 'undefined' ) {
this.curfld = this.Count++;
this.fld_arr[this.curfld] = new myfield();
this.fldname_idx_arr[fldName.Count] = this.curfld;
}
else {
this.curfld = this.fldname_idx_arr[fldName]

}
this.fld_arr[this.curfld].name = fldName;
this.fld_arr[this.curfld].value = fldValue;
this.fld_arr[this.curfld].type = "string";
this.fld_arr[this.curfld].attributes = "";
return this.curfld;
}

return this.item(idx);
}


function myfield()
{
this.name = null;
this.value = null;
this.type = null;
this.attributes = null;
}



//var rs1 = new myrs(this);

var tstflds1 = new myFields();
var col1idx = tstflds1.append("col1", "this is a value for col1");
alert("col1idx = " + col1idx);
alert("0 name=[" + tstflds1.item(0).name + "] value=[" + tstflds1.item(0).valu + "]");


but where this also works...
alert("0 name=[" + tstflds1(0).name + "] value=[" + tstflds1(0).value + "]");

ie. javascript that impliments the ADO Fields collection
where item is the default property, from ADO Ref...

Item Property
Indicates a specific member of a collection, by name or ordinal number.

Syntax
Set object = collection.Item ( Index )
Return Value
Returns an object reference.

Parameters
Index
A Variant expression that evaluates either to the name or to the ordinal number of an object in a collection.
Remarks
Use the Item property to return a specific object in a collection. If Item cannot find an object in the collection corresponding to the Index argument, an error occurs. Also, some collections don't support named objects; for these collections, you must use ordinal number references.

The Item property is the default property for all collections; therefore, the following syntax forms are interchangeable:

[Edited by rshep2 on 18-Apr-12 02:53]

--
rshep2
19-Apr-12 12:36
http://www.howtocreate.co.uk/tutorials/javascript/objects

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
20-Apr-12 01:18
For the life of me, I can't see where this shows how to create default methods.
Can you point me tio the correct section?

--
rshep2
21-Apr-12 13:32
You probably can't then AND is this client side javascript or server side?

The javascript core will return 'undefined' if a property or method does not exist for an object

Also: "collection" is a Visual Basic/vbScript term as well, in javascript all objects are associative arrays, so are you sure you are on the right track.

And to be honest, Visual Basic/VbScript (client site and server side) is the only language I have ever used that is sloppy enough to allow you to drop the '.value' from a property declaration and still get the correct return value.

[Edited by chrishirst on 21-Apr-12 13:33]

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
22-Apr-12 02:22
It is client side Javascript
The existing code used the MS Tabular Data Control
to access local CSV files to produce reports offline.
The existing code base uses Fields(x).value and is working.
I have replaced the MS TDC with my own implimentation
in Javascript, but it does not impliment the Fields collection
correctly. At the momemt I have replaced Fields(x).value with Fields[x}.value
Maybe default methods are not possible to impliment in Javascript.
My intenetion is to arrive at a single code base that usesd both
the MS TDC ActiveX object when running on IE, but uses my
Javascript TDC code when running on Apple Safari.
Looks like I will have to remove all use of the default method
for the Fields object.

[Edited by rshep2 on 22-Apr-12 02:24]

--
rshep2
22-Apr-12 07:38
Client side javascript ... You can't.

Because javascript is 'Object Orientated' it uses "prototyping" to determine what value to return for a unknown property or method. This means that it will "bubble up" the search from your derived object/class to the original object or class.

With javascript being a "soft" language, you can redefine core functions, by creating your own using that same name, as I do for my improved javascript alert at -> http://www.modtalk.co.uk/article/chris-hirst/another-alert/
Or you could intercept/reroute the core by writing your own property 'get" handler to include a default value if the javascript core handler returns with 'undefined'.

You are aware that javascript in a browser context is NOT allowed access to the local client filing system other than the 'cookie' and 'history' locations? Unless the browser security has been deliberately lowered to allow it. Which has far more risky connotations to it.

ActiveX objects are allowed to, because they run in the 'user' context not the 'browser' context, this is one of the things that makes IE a easier target for "hijacking".

However if you are working in a 'closed environment' such as a company network you can at least be reasonably assured that only the one browser may/will be in use.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
22-Apr-12 23:43
It is the intention that Safari users must be setup as
online users only.
I have both version running on a test server, and wish
to merge the code bases, but still use the MS TDC if
IE is used.

> Or you could intercept/reroute the core by writing your own > property 'get" handler to include a default value if the
> javascript core handler returns with 'undefined'.

Can you point me to some docs that explain property 'get' handlers

[Edited by rshep2 on 22-Apr-12 23:47]

--
rshep2

 
New posts
Old posts

Follow Elated