Jump to content
toufik

Delphi REST showing only one row on the client side ?

Recommended Posts

hi every one
can some one help me with problem
I'm using Delphi REST with server and client but when i tried to show data on the client side its show only one row for some reason,
what did i do wrong ?
PS : I'm using Delphi roi and restdataware 
the video down show what I'm deal with ; any help will be very appreciated ^^ thank you 
on the client side i'm using this code 
 

procedure listv;
var

    jsonObj : TJsonObject;
    json, sucesso, erro,id_store ,nom_store, phone_saler: string;
begin
  //  FrmLogin.FloatAnimation2.Stop;
   // FrmLogin.FloatAnimation3.Stop;
  if FrmLogin.listvreq.Response.JSONValue = nil then
    begin
      //  FrmLogin.ExibirCampos;
        ShowMessage('خطأ في إنشاء الحساب (JSON غير صالح)');
        exit;
    end;

    try
        json := FrmLogin.listvreq.Response.JSONValue.ToString;
        jsonObj := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(json), 0) as TJSONObject;

        sucesso := jsonObj.GetValue('sucesso').Value;
        erro := jsonObj.GetValue('erro').Value;
      id_store := jsonObj.GetValue('id_store').Value;
         nom_store := jsonObj.GetValue('nom_store').Value;
          if sucesso <> 'S' then
        begin
         //   FrmLogin.ExibirCampos;
            ShowMessage(erro);
            exit;
        end
        else

          // showmessage('تم احضار بيانات: ' + id_store+nom_store);

          //  FrmLogin.ExibirCampos;///

         //   FrmLogin.ListView1.Items.Clear();
    finally
        jsonObj.DisposeOf;
    end;

    end;

  procedure listverr(Sender: TObject);
begin
    if Assigned(Sender) and (Sender is Exception) then
    begin
      //  FrmLogin.ExibirCampos;
        showmessage(Exception(Sender).Message);
    end;
end;

procedure TFrmLogin.StartLogin2;
begin
  TThread.CreateAnonymousThread(
    procedure
    var
      Success: Boolean;
    begin
      try
        RequestLogin.Execute;
        Success := RequestLogin.Response.Status.Success;
      except
        Success := False;
      end;
      TThread.Queue(nil,
        procedure
        begin
          AfterLogin2(Success);
        end
      );
    end
  ).Start;
end;

procedure TFrmLogin.AfterLogin2(Success: Boolean);
 begin
    if Success then
   begin

listvreq.Params.Clear;
listvreq.AddParameter('type_store',ComboBox1.Selected.Text);  ///   ****
listvreq.ExecuteAsync(listv, true, true, listverr);
   end
   else
  begin
showmessage (' عفوا ...! لايمكن الاتصال بالخادم حاليا يرجى المحاولة لاحقا')
  end;


on server side :

 


procedure Tdm.DWEventsEventslistvReplyEvent(var Params: TDWParams;
  var Result: string);
var
    type_store, erro : string;
    usuario : TUsuario;
    json : TJsonObject;
begin
    try
        sleep(4000);
        type_store := Params.ItemsString['type_store'].AsString;

        json := TJsonObject.Create;

        usuario := TUsuario.Create(dm.conn);
        usuario.type_store := type_store;

        if NOT usuario.listv(erro) then
        begin
            //{"sucesso": "N", "erro":"Usuلrio nمo informado", "codusuario":"0"}
            json.AddPair('sucesso', 'N');
            json.AddPair('erro', erro);
         json.AddPair('id_store', '');
           json.AddPair('nom_store', '');
        end
        else
        begin
            json.AddPair('sucesso', 'S');
            json.AddPair('erro', '');
          json.AddPair('id_store', usuario.id_store.ToString);
             json.AddPair('nom_store', usuario.nom_store);
        end;

        Result := json.ToString;

    finally
        json.DisposeOf;
        usuario.DisposeOf;
    end;

 

and in class  i add called unit usuario
 

function TUsuario.listv(out erro: string): Boolean;
var
    qry : TFDQuery;

begin
    try
        qry := TFDQuery.Create(nil);
        qry.Connection := FConn;

        with qry do
        begin
            Active := false;
            SQL.Clear;
SQL.Add('SELECT * from saler  WHERE type_store = :any ');
             ParamByName('any').Value := type_store;
                    Active := true;

                        if RecordCount > 0 then
            begin
              id_store := FieldByName('id_store').AsInteger;
                  nom_store := FieldByName('nom_store').AsString;
             erro := '';
                Result := true;
            end
            else
            begin
              //  id_store := 0;
                erro := 'تعذر جلب بيانات المعلنين';
                Result := false;
            end;

            DisposeOf;
        end;

    except on ex:exception do
    begin
        erro := 'خطأ في التحقق من صحة تسجيل الدخول: ' + ex.Message;
        Result := false;
    end;
    end;


 

 

Edited by toufik

Share this post


Link to post

First, do some debugging and find out if the record "disappears" on the server side (query, or in the JSON transformation), or on the client side (store raw JSON, review contents...).

  • Like 1

Share this post


Link to post
On 5/3/2021 at 5:38 AM, eivindbakkestuen said:

First, do some debugging and find out if the record "disappears" on the server side (query, or in the JSON transformation), or on the client side (store raw JSON, review contents...).

thanks for taking time to reply i found that i did not add an array , tjsonarray , that fix it for me

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×