[SOLVED] SDFDataset lazarus / 61-Beginners ---------------------------------------------------------------------- scons · 2017-07-10 21:04 Hi all, Following question is just out of curiosity. Regarding this topic I have been doing some test with SQLite. I have come up with following SQL commands: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.BtnSYNCClick(Sender: TObject);var  s: string;  h: integer;begin  s := DBGrid1.SelectedField.AsString;  h := DBGrid1.Columns.Items[0].Field.AsInteger;  SQLQuery1.Close;  SQLQuery1.SQL.Clear;  SQLQuery1.SQL.Add('update PROJECT set TRANSPORT = "' +s+ '" where HPOS = "' +IntToStr(h)+ '"');  SQLQuery1.ExecSQL;  SQLTransAction1.Commit;  SQLQuery1.Close;end;  Which basically sets all the fields in a column the same as the selected field if the value of Column[0] matches (selection from a DBGrid Picklist). Second one is: Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SELECT TRANSPORT, SUM(WEIGHT) AS TOTALWEIGHTFROM PROJECTGROUP BY TRANSPORT; then Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UPDATE TRANSPORTSETTOTALWEIGHT = (SELECT TOTALWEIGHT FROM SUMTRANSWEIGHT WHERE TRANSPORT = TRUCK) An SQL query to create a view and update a table which is used (also in a DBGrid) to show weight totals Can you do these things also within an SDFdataset ? Just for speed comparison it would be nice to see differences, if there are any ... (sqlite = database, sdfdataset = memory ?). ---------------------------------------------------------------------- scons · 2017-08-30 23:47 Okay, had some time left to try some more this is what I have so far: I have 2 sdfdatasets filled from different csv files with different content. However 1 dataset contains the same values as the other on, althought they are less in quantity. Sdfdataset1 contains: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PNR;MTL;QTY; ... ;SLR;SRR; ... ;LGT; ... ;RLR;RRR, ...75001;Alu;2; ... ;0.0;0.0; ... ;0; ... ;0.0;0.3; ...75002;Alu;3; ... ;0.1;0.0; ... ;501; ... ;0.0;0.3; ...75008;Alu;1; ... ;0.0;0.0; ... ;0; ... ;0.0;0.0; ...40002;Alu;1; ... ;0.0;0.2; ... ;0; ... ;0.0;0.0; ...40001;Alu;3; ... ;0.0;0.0; ... ;213; ... ;0.0;0.0; ...40003;Alu;15; ... ;0.0;1.0; ... ;111; ... ;0.0;1.0; ...45001;Alu;201; ... ;0.0;0.0; ... ;0; ... ;0.0;0.0; ......  Sdfdataset2 contains only this: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i PNR1;LGT;ZG HL1;ZGHL2;ZGHR1;ZGHR240001;0;0.0;0.2;0.0;0.040002;0;0.0;0.0;0.0;0.0400 03;0;0.0;1.0;0.0;1.075008;0;0.0;0.0;0.0;0.0  So I want to update sdfdataset 2 with some values of sdfdataset1 PNR and PNR1 contain the same numbers (data) and will be used as a match. so if PNR1 matches PNR, LGT, ZGHL1, ZGHL2, ZGHR1, ZGHR2 should be updated with the values from LGT, SLR, SRR, RLR, RRR This is what I have so far but it stays on the first value of sdfdataset1 (it gets stuck in a loop) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       F := SdfDataSet1.FieldByName('PNR');      G := SdfDataSet2.FieldByName('PNR1');       SdfDataSet2.DisableControls;    try        SdfDataSet2.First;        while not SdfDataSet2.EOF do       SdfDataSet1.First;         while not SdfDataSet1.EOF do            if VarSameValue(F.Value, G.Value) then              begin              //writeln('succes');                SdfDataSet2.Fields[x].AsInteger := SdfDataSet1.Fields[y].AsInteger;              SdfDataSet2.Fields[v].AsInteger := SdfDataSet1.Fields[w].AsInteger;                ...                Exit;           end else begin           writeln('no succes');         SdfDataSet1.Next;           end;           SdfDataSet2.Next;       finally         SdfDataSet2.EnableControls;       end;  So what am I doing wrong here ? ---------------------------------------------------------------------- scons · 2017-08-31 12:52 After some hours of testing, this seems to work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    F := SdfDataSet1.FieldByName('PNR');   SdfDataSet1.DisableControls;   SdfDataSet2.DisableControls;     SdfDataSet2.First;    while not (SdfDataSet2.EOF) do    begin      s1 := SdfDataSet2.FieldByName('PNR1').AsString;      SdfDataSet1.First;    while not (SdfDataSet1.EOF) do      begin        s2 := SdfDataSet1.FieldByName('PNR').AsString;        s3 := SdfDataSet1.FieldByName('SL').AsString;        s4 := SdfDataSet1.FieldByName('SR').AsString;        s5 := SdfDataSet1.FieldByName('FL').AsString;        s6 := SdfDataSet1.FieldByName('FR').AsString;        if VarSameValue(F.Value, s1) then        begin          writeln('succes : ' + s1 + ' - ' + s2);          SdfDataSet2.Edit;          SdfDataSet2.FieldByName('ZAAGHL1').AsString := s3;          SdfDataSet2.FieldByName('ZAAGHL2').AsString := s4;          SdfDataSet2.FieldByName('ZAAGHR1').AsString := s5;          SdfDataSet2.FieldByName('ZAAGHR2').AsString := s6;          SdfDataSet2.Post;        end        else        begin          writeln('no succes : ' + s1 + ' - ' + s2);        end;        SdfDataSet1.Next;      end;      SdfDataSet2.Next;    end;    SdfDataSet1.EnableControls;    SdfDataSet2.EnableControls; Now I have to lay down for a while, I have a headache ...