3

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

RBA
  • 12,337
  • 16
  • 79
  • 126
Alex Kirov
  • 217
  • 4
  • 16
  • 1
    Please try formatting your question correct to enhance readability... – Nidhoegger Jan 26 '17 at 18:36
  • You need to ensure all your code is formatted... but additionally `StringGrid1.Cells[1,i]:=AResource.Value.AsString;` looks like it sets the same value every time so... maybe start there? – Cody G Jan 26 '17 at 19:23
  • Hi Guys ,I need help! When I extract file path with ExtractFilePath (paramstr(0)) I'm getting this: C:\Users\Admin\Documents\Embarcadero\Studio\Projects\example13.02\Win32\Debug but I need to go 2 step back. C:\Users\Admin\Documents\Embarcadero\Studio\Projects\example13.02\ I don't know, How? ExtractFilePath (paramstr(0))) how to make 2 step back ../../ – Alex Kirov Feb 13 '17 at 12:07

1 Answers1

0

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

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • Dear, Tom Brunberg. I need your help http://stackoverflow.com/questions/42005612/delphi-login-form-using-app-tethering-by-connecting-to-sqlite-database – Alex Kirov Feb 02 '17 at 15:16
  • @Alex I'll take a look in about 2 hours – Tom Brunberg Feb 02 '17 at 15:32
  • Dear, Tom. I need your help! stackoverflow.com/questions/42153215/how-to-get-images-from-server-using-app-tethering – Alex Kirov Feb 10 '17 at 06:57
  • Bro, did u try? http://stackoverflow.com/questions/42153215/how-to-get-images-from-server-using-app-tethering – Alex Kirov Feb 10 '17 at 11:21
  • When I extract file path with ExtractFilePath (paramstr(0)) I'm getting this: C:\Users\Admin\Documents\Embarcadero\Studio\Projects\example13.02\Win32\Debug but I need to go 2 step back. C:\Users\Admin\Documents\Embarcadero\Studio\Projects\example13.02\ I don't know, How? ExtractFilePath (paramstr(0))) how to make 2 step back ../../ – Alex Kirov Feb 13 '17 at 12:08
  • Dear, Tom Brunberg. I need your help http://stackoverflow.com/questions/42431336/delphi-how-to-call-actionlist-on-button – Alex Kirov Feb 24 '17 at 05:54