Acces to member of TJSArray

Hi,

I create a siple TJSArray with 4 TJSObject.

Later, how can i acces a members of this TJSArray ?

I create the TJSObject like this:

js:=TJSArray.new;

jo:=TJSObject.new;
jo['codi']:=1;
jo['nom']:='Nom 1';
js.push(jo);

jo:=TJSObject.new;
jo['codi']:=2;
jo['nom']:='Nom 2';
js.push(jo);

Later i want to send all 'nom' to TWebMemo in for statement. But i not know how can i reference to any object.

Thanks !

You should be able to access an array element with:

js.Elements[index]: JSValue

Sorry, i do'nt know how do this.

This is my code now:

var
jsa: TJSArray;
pos: integer;
jo: TJSObject;
jv: JSValue;
begin
jsa:=TJSArray.new;

jo:=TJSObject.new;
jo['codi']:=1;
jo['nom']:='Nom 1';
jsa.push(jo);

jo:=TJSObject.new;
jo['codi']:=2;
jo['nom']:='Nom 2';
jsa.push(jo);

console.log(inttostr(jsa.Length));

console.log(jsa);

for pos:=0 to jsa.Length-1 do
begin
jv:=jsa.Elements[pos];
webmemo2.lines.add(string(jv));
end;
end;

I do not know how convert JSValue to string in order to put in a TWebMemo control.
The line on i try to assign a value of item of jsovalue is not correct.

What is the correct way to do is ?

This is only a test code. Really i want to know how can i acces to TWebClientDataSet.Row that is a TJSArray.

For me is more conformtable acces to the data contained in a DataSet using the dataset properties like first... fieldbyname, etc... but i want to know how can i work with TJSArray contanined in a Row property.

Thanks !!!

Sorry another time,

The code is incorrect because the output that can i see in the TWebMemo is:

[Object Object]
[Object Object]

Tks

Hi,

I found the solution of my problem:

The message that i see in the memo is "Object" because i try to "print" an Object. JSValue seems an javascript object.

Firs i must convert this json avascript object to json pascal object, and then work with it.

I applied this method to my fist objective. Work with TWebClientDataSet.Row property.

My code is this:

var
txt: String;
jsa: TJSArray;
pos: integer;
jo: TJSObject;
jv: JSValue;

Lobj: TJSObject;
begin
jsa:=WebClientDataSet1.Rows;

console.log(jsa);

for pos:=0 to jsa.flength-1 do
begin
jv:=jsa.Elements[pos];
lObj:=toObject(jv);
txt:=string(lObj['title']);
webmemo2.lines.add(txt);
end;
end

NOTE: One column of the WebClientDataSet is named "title".

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.