#9 Incorerct name detection, deletion or addition , with code e

open
nobody
None
9
2014-06-17
2009-11-17
No

To addition to ticket below, I create a test code:

var
idx :Integer;
JsBase :TlkJSONobject; //TlkJSONbase;
begin
JsBase := TlkJSONstreamed.LoadFromFile('c:\start.json') as TlkJSONobject; //see attachments

idx := JsBase.IndexOfName('LASTUPDATE');
JsBase.Delete(idx);
JsBase.Add('LASTUPDATE', 0);

idx := JsBase.IndexOfName('CHECKDATE');
JsBase.Delete(idx);
JsBase.Add('CHECKDATE', 0);

//here state is:
// JsBase.NameOf[0] = 'LASTUPDATE'
// TlkJSON.GenerateText(JsBase.Child[0]) = '"LASTUPDATE":0'
// but
// JsBase.IndexOfName('TTODGAgent') also == 0 !!!
// TlkJSON.GenerateText(JsBase.FieldByIndex[0]) == '{"HOST":"127.0.0.1","PORT":8082,"LOGIN":"admin2..... i.e. text of 'TTODGAgent'
//for example

idx := JsBase.IndexOfName('TTODGAgent');
if idx>=0 then begin;
JsBase.Delete(idx);
FreeAndNil(JsBase);
end;

//here no 'TTODGAgent' but 'LASTUPDATE' will be deleted!!!
//see screenshot in previous ticket
end;

Discussion

  • SergeyNikitin

    SergeyNikitin - 2009-11-17
     
    Attachments
  • SergeyNikitin

    SergeyNikitin - 2009-11-17
    • priority: 5 --> 9
    • summary: Incorerct file name detection or deletion --> Incorerct name detection, deletion or addition , with code e
     
  • SergeyNikitin

    SergeyNikitin - 2009-11-17

    Bu is inside delete.

    Try this:

    JsBase := TlkJSONstreamed.LoadFromFile('c:\start.json') as TlkJSONobject;

    idx := JsBase.IndexOfName('CHECKDATE');
    JsBase.Delete(idx);

    //now check here, for example:
    //JsBase.IndexOfName('TTODGAgent'); returns 1 (really==0)
    //JsBase.IndexOfName('LASTUPDATE') returns 0 (really==1);

     
  • SergeyNikitin

    SergeyNikitin - 2009-11-17

    once more example:

    JsBase := TlkJSON.ParseText('{"CHECKDATE":0,"LASTUPDATE":0,"TTODGAgent":{"HOST":"127.0.0.1"}}') as TlkJSONobject;

    idx := JsBase.IndexOfName('CHECKDATE');
    JsBase.Delete(idx);

    idx := JsBase.IndexOfName('TTODGAgent');
    JsBase.Delete(idx);

    strText := TlkJSON.GenerateText(JsBase);

    now strText is equal to '{"TTODGAgent":{"HOST":"127.0.0.1"}}'
    !!!

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks