delphidelphi-xe8stringgrid

Paging Server Side Data On Client in Delphi XE using App tethering


I have Server And Client App.

From Server side there are 2 buttons.

1st button "Display Data On Server". 2nd button "Send Data to Client". In a Server side i'm using FDQuery1, SringGrid1, TetheringManager1 and TetheringAppProfile1.

From Client Side only 1 button "Connect". In a Client Side I'm using StringGrid1, TetheringManager1 and TetheringAppProfile1

So First Client Connecting to the Server then Server Side sending data to client.

Server "Send Data to Client" button

Code:

procedure TForm1.Button2Click(Sender: TObject);
var rec:integer;
begin
  FDQuery1.SQL.Text := 'SELECT * FROM names';
  FDQuery1.Open;
  rec := FDQuery1.RecordCount;
  FDQuery1.First;

  if rec>0 then
  begin
    while not FDQuery1.Eof do
    begin
      TetheringAppProfile1.Resources.FindByName('Vefa').Value:=FDQuery1.FieldByName('Name').AsString;
      FDQuery1.Next;
    end;
  end;

Client Side Receive

Code:

procedure TForm2.TetheringAppProfile1Resources1ResourceReceived(
  const Sender: TObject; const AResource: TRemoteResource);
var i:integer;
begin
  for i := 0 to TetheringAppProfile1.Resources.Count do
    StringGrid1.Cells[1,i]:=AResource.Value.AsString;
end;

But When I send data from Server to Client I see like this:

IMAGE


Solution

  • You can collect the names into a TStringList and then send that either as a string, using the TStringList.Text property, or as a stream.

    To send as a string (and assuming a resource name = NameList), the SendDataClick event handler could look like this:

    procedure TServerForm.btnSendDataClick(Sender: TObject);
    var
      sl: TStringList;
    begin
      sl := TStringList.Create;
      try
        sl.Add(StringGrid1.Cells[1, 1]);
        sl.Add(StringGrid1.Cells[1, 2]);
        sl.Add(StringGrid1.Cells[1, 3]);
        TetheringAppProfile1.Resources.FindByName('NameList').Value := sl.Text;
      finally
        sl.Free;
      end;
    end;
    

    I simply copied the names from the grid, you could do it directly from the db records.

    And the client OnResourceReceived:

    procedure TClientForm.TetheringAppProfile1Resources2ResourceReceived(
      const Sender: TObject; const AResource: TRemoteResource);
    var
      sl: TStringList;
      i: integer;
    begin
      sl := TStringList.Create;
      try
        sl.Text := AResource.Value.AsString;
        for i := 0 to sl.Count-1 do
          StringGrid1.Cells[1, i+1] := sl[i];
      finally
        sl.Free;
      end;
    end;
    

    I suggest you also read about passing streams in Malcolm Groves blog