Anna Kirova
asked on
How to Get Images From Server using App Tethering
I've 2 Apps Let's call Server And Client.
I'm using Delphi-xe8. App ->Multi-Device Application
In Both Side using: App tethering[tManager,tAProfi le], SQLite Database.
In Server SQLite Database I've 6 images. I would like to View that images In Client Side.
In Client Side I've 6 [TImage].
When I Click Button 'Get Image List' I'm getting 6 images with the same view.
I would like 6 images view differently.->[Get From Server Database]
Client "Get Image List" button Code:
procedure TForm1.GetImgLstClick(Send er: TObject);
begin
tAProfile.SendString(tMana ger.Remote Profiles.F irst,'GetI mages','') ;
end;
Server Received Code:
procedure TForm2.tAProfileResourceRe ceived(con st Sender: TObject;
const AResource: TRemoteResource);
var
MS1:TMemorystream;
begin
if AResource.Hint='GetImages' then
begin
MS1:=TMemorystream.Create;
rQuery.Close;
rQuery.SQL.Clear;
rQuery.SQL.Add('select image from users');
rQuery.Open;
while not rQuery.Eof do
begin
tblobField(rQuery.FieldByN ame('image ')).SaveTo Stream(MS1 );
Image1.Bitmap:=nil;
rQuery.Next;
end;
tAProfile.SendStream(tMana ger.Remote Profiles.F irst,'Send Images',MS 1);
end;
end;
Client Received Code:
procedure TForm1.tAProfileResourceRe ceived(con st Sender: TObject;
const AResource: TRemoteResource);
var
MS:TMemoryStream;
begin
if AResource.Hint='SendImages ' then
begin
Image1.Bitmap.LoadFromStre am(AResour ce.Value.A sStream);
Image2.Bitmap.LoadFromStre am(AResour ce.Value.A sStream);
Image3.Bitmap.LoadFromStre am(AResour ce.Value.A sStream);
Image4.Bitmap.LoadFromStre am(AResour ce.Value.A sStream);
Image5.Bitmap.LoadFromStre am(AResour ce.Value.A sStream);
Image6.Bitmap.LoadFromStre am(AResour ce.Value.A sStream);
end;
end;
I'm using Delphi-xe8. App ->Multi-Device Application
In Both Side using: App tethering[tManager,tAProfi
In Server SQLite Database I've 6 images. I would like to View that images In Client Side.
In Client Side I've 6 [TImage].
When I Click Button 'Get Image List' I'm getting 6 images with the same view.
I would like 6 images view differently.->[Get From Server Database]
Client "Get Image List" button Code:
procedure TForm1.GetImgLstClick(Send
begin
tAProfile.SendString(tMana
end;
Server Received Code:
procedure TForm2.tAProfileResourceRe
const AResource: TRemoteResource);
var
MS1:TMemorystream;
begin
if AResource.Hint='GetImages'
begin
MS1:=TMemorystream.Create;
rQuery.Close;
rQuery.SQL.Clear;
rQuery.SQL.Add('select image from users');
rQuery.Open;
while not rQuery.Eof do
begin
tblobField(rQuery.FieldByN
Image1.Bitmap:=nil;
rQuery.Next;
end;
tAProfile.SendStream(tMana
end;
end;
Client Received Code:
procedure TForm1.tAProfileResourceRe
const AResource: TRemoteResource);
var
MS:TMemoryStream;
begin
if AResource.Hint='SendImages
begin
Image1.Bitmap.LoadFromStre
Image2.Bitmap.LoadFromStre
Image3.Bitmap.LoadFromStre
Image4.Bitmap.LoadFromStre
Image5.Bitmap.LoadFromStre
Image6.Bitmap.LoadFromStre
end;
end;
ASKER
what if There are 10000 images ???
ASKER
This is not solution! I need Splite Stream . But I don't know How??? as an example http://stackoverflow.com/questions/42056070/how-to-split-string-by-splitstring-or-delimiter I now how to split String but I don't know Stream ;((((((((((
You don't need split stream... I put example for just showing my idea. So, why to load 1000 images at the same time.
Send image with index as I show... (little precise example...):
Send image with index as I show... (little precise example...):
...
tAProfile.SendString(tManager.RemoteProfiles.First,'GetImage_1','');
...
tAProfile.SendString(tManager.RemoteProfiles.First,'GetImage_999','');
...
procedure TForm2.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
MS1:TMemorystream;
sImageIdx: String;
i: Integer;
begin
sImageIdx:='';
if Copy(AResource.Hint,1,Length('GetImage_'))='GetImage_' then
begin
i := Pos('_',AResource.Hint);
sImageIdx:= Copy(AResource.Hint, i+1, Length(AResource.Hint)-i);
end;
if Length(sImageIdx)>0 then
begin
MS1:=TMemorystream.Create;
rQuery.Close;
rQuery.SQL.Clear;
rQuery.SQL.Add('select image from users where xxxx='+sImageIdx);
rQuery.Open;
while not rQuery.Eof do
begin
tblobField(rQuery.FieldByName('image')).SaveToStream(MS1);
Image1.Bitmap:=nil;
rQuery.Next;
end;
tAProfile.SendStream(tManager.RemoteProfiles.First,'SendImage_'+sImageIdx,MS1);
end;
end;
.... <continued>... so, please load only few images at the time, all other when they needed ... (when list scroll down... and user does not have image yet)
Ah.... you open another/same question ....
Instead you loose your energy on new question - you should try to understand whole idea ...
Client side code:
you can even implement one sending command ...
...then you can translate this into several sending commands...
Instead you loose your energy on new question - you should try to understand whole idea ...
Client side code:
procedure TForm1.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
MS:TMemoryStream;
sImageIdx: String;
i: Integer;
begin
sImageIdx:='';
if Copy(AResource.Hint,1,Length('SendImage_'))='SendImage_' then
begin
i := Pos('_',AResource.Hint);
sImageIdx:= Copy(AResource.Hint, i+1, Length(AResource.Hint)-i);
end;
if Length(sImageIdx)>0 then //1 or 2 or ....
begin
if sImageIdx='1' then
Image1.Bitmap.LoadFromStream(AResource.Value.AsStream);
if sImageIdx='2' then
Image2.Bitmap.LoadFromStream(AResource.Value.AsStream);
....
end;
end;
you can even implement one sending command ...
...
tAProfile.SendString(tManager.RemoteProfiles.First,'GetImages','');
...
...then you can translate this into several sending commands...
procedure TForm2.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
MS1:TMemorystream;
sImageIdx: String;
i: Integer;
begin
sImageIdx:='';
if Copy(AResource.Hint,1,Length('GetImage_'))='GetImage_' then
begin
i := Pos('_',AResource.Hint);
sImageIdx:= Copy(AResource.Hint, i+1, Length(AResource.Hint)-i);
if Length(sImageIdx)>0 then
begin
MS1:=TMemorystream.Create;
rQuery.Close;
rQuery.SQL.Clear;
rQuery.SQL.Add('select image from users where xxxx='+sImageIdx);
rQuery.Open;
while not rQuery.Eof do
begin
tblobField(rQuery.FieldByName('image')).SaveToStream(MS1);
Image1.Bitmap:=nil;
rQuery.Next;
end;
tAProfile.SendStream(tManager.RemoteProfiles.First,'SendImage_'+sImageIdx,MS1);
end;
end
else if AResource.Hint='GetImages' then
begin
MS1:=TMemorystream.Create;
rQuery.Close;
rQuery.SQL.Clear;
rQuery.SQL.Add('select image from users');
rQuery.Open;
i := 0;
while not rQuery.Eof do
begin
Inc(i);
MS1.Clear;
tblobField(rQuery.FieldByName('image')).SaveToStream(MS1);
Image1.Bitmap:=nil;
tAProfile.SendStream(tManager.RemoteProfiles.First,'SendImage_'+IntToStr(i),MS1); //send each image in a separate cmd ...
rQuery.Next;
end;
end;
end;
ASKER
Actually, I'm new to Programming. it seems difficult to me . 1 ? How to Get All Images From Server Database to Client Database Directly by one click?
IF I Click Client App Click Btn, I should get All images From Server SQLite Database to Client SQLite Database.
IF I Click Client App Click Btn, I should get All images From Server SQLite Database to Client SQLite Database.
As I show in my example - when detect GetImages command - then go into loop in a resulting set (from DB) - this is mainly copy of your code - but I force to send for each row - new command - which is recognize on client part (upper modified code).
ASKER
I need easiest way plz!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Sinisa Vuk Thank you very much!
Open in new window
in client ..
Open in new window