Delphi:如何通过使用应用程序绑定从服务器数据库获取所有图像? [英] Delphi: How to Get All Images From Server Database by using App tethering?
问题描述
EveryBody!
Hi, EveryBody!
我有客户端和服务器。
我使用的是Delphi-xe8。应用程序 - >多设备应用程序
I'm using Delphi-xe8. App ->Multi-Device Application
客户端和服务器正在使用应用系统绑定,SQLite数据库。
Both Client and Server are using App tethering, SQLite Database.
当服务器将图像添加到数据库时,它完美地添加了
When Server adding image to database, it's perfectly adding,
但客户端点击获取图像列表按钮时,在客户端。客户只接收一个图像[我想要所有图像]。
but In a Client side when Client click "Get Image List" button. Client Recieve only one image [I want All images].
1。 QUE:如何获取从服务器数据库到客户端数据库的所有映像。通过使用应用程序绑定[SendStream]?我认为AResource.Value.AsStream的问题需要拆分,如何...?
1. Quation: How to get All images from Server Database to Client Database. by using App tethering[SendStream]? I think Problem with AResource.Value.AsStream need to Splite, How...???
2。估价:如何从服务器数据库复制所有图像并保存在客户端创建的文件夹中[Client\db\images]?
2. Quation: How to copy all Images From Server Database and save on Client Created folder[Client\db\images] ?
获取图像列表按钮代码
procedure TForm1.GetImgBtnClick(Sender: TObject);
begin
tAProfile.SendString(tManager.RemoteProfiles.First,'GetImages','get');
end;
服务器端:
procedure TForm2.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
MS:TMemorystream;
begin
if AResource.Hint='GetImages' then
begin
MS:=TMemorystream.Create;
// ShowMessage(AResource.Value.AsString); // msg from client 'get'
while not rQuery.Eof do
begin
tblobField(rQuery.FieldByName('image')).SaveToStream(MS1);
Image1.Bitmap:=nil; // Если не занулить будет ошибка
// Image1.bitmap.LoadFromStream(MS);
rQuery.Next;
end;
tAProfile.SendStream(tManager.RemoteProfiles.First,'SendImages',MS); //Sending Images to Client MS
end;
end;
客户端:
procedure TForm1.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
begin
if AResource.Hint='SendImages' then
begin
// Image1.Bitmap.LoadFromStream(AResource.Value.AsStream);
rQuery.Insert;
TBlobField(rQuery.FieldByName('image')).LoadFromStream(AResource.Value.AsStream);
rQuery.Post;
end;
end;
推荐答案
如何获取全部图像从服务器数据库通过使用应用程序绑定?
How to Get All Images From Server Database by using App tethering?
实际上,这是非常简单的做法,下面我做了。
Actually, this is very simple to do, the way I've done it below.
我希望通过将您的应用与下面的两个对比进行比较,您可以计算出
您需要做什么才能使您正常工作或者如果没有,至少可以帮助
改进你的q来关注确切的问题。
I hope that by comparing your apps with the two below, you'll be able to figure out what you need to do to get yours to work correctly or, if not, it at least might help refine your q to focus on what the exact problem is.
停止细节,如没有你的数据可用在这里,使用FMX和Live Bindings
(以及您可能如何使用它们)阻碍了我的应用程序,您可以在Delphi Samples / Data文件夹中找到BioLife.CDS数据。我基于Malcolm Groves教程中的两个应用程序的代码这里
To stop details like not having your data available here, and use of FMX and Live Bindings (and how you might be using them) getting in the way, I based my apps on the BioLife.CDS data you'll find in your Delphi Samples/Data folder. I based the code of the two apps on Malcolm Groves tutorial here
http://www.malcolmgroves.com/blog/?p=1854
在这两个应用程序中,我有一个ClientDataSet ,DataSource,DBGrid,DBNavigator和DBImage在每个应用程序中,
与您在最小的db-aware-101应用程序中所期望的完全相同。
and in both apps I have a ClientDataSet, DataSource, DBGrid, DBNavigator and DBImage in each app, connected up exactly as you'd expect in a minimal db-aware-101 application.
系统绑定机制将第一个应用程序的CDS数据作为流发送到第二个应用程序,
使用TClientDataSet SaveToStream
和 LoadFromStream
方法。
The tethering mechanism sends the first app's CDS data to the second app as a stream,
using the TClientDataSet SaveToStream
and LoadFromStream
methods.
这两个应用程序首次进行零调试。
The two apps worked first time with zero debugging.
App1代码:
TApp1Form = class(TForm)
TetheringManager1: TTetheringManager;
TetheringAppProfile1: TTetheringAppProfile;
DBImage1: TDBImage;
btnConnect: TButton;
Label1: TLabel;
CDS1: TClientDataSet;
CDS1SpeciesNo: TFloatField;
CDS1Category: TStringField;
CDS1Common_Name: TStringField;
CDS1SpeciesName: TStringField;
CDS1Lengthcm: TFloatField;
CDS1Length_In: TFloatField;
CDS1Notes: TMemoField;
CDS1Graphic: TGraphicField;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
btnSendStream: TButton;
[...]
end;
[...]
procedure TApp1Form.btnConnectClick(Sender: TObject);
begin
TetheringManager1.AutoConnect;
end;
procedure TApp1Form.btnSendStreamClick(Sender: TObject);
begin
CDSToStream;
end;
procedure TApp1Form.FormCreate(Sender: TObject);
begin
CDS1.Open;
Caption := Format('App1 : %s', [TetheringManager1.Identifier]);
end;
procedure TApp1Form.TetheringManager1PairedToRemote(const Sender: TObject; const
AManagerInfo: TTetheringManagerInfo);
begin
Label1.Caption := Format('Connected : %s %s',
[AManagerInfo.ManagerIdentifier,
AManagerInfo.ManagerName]);
end;
procedure TApp1Form.CDSToStream;
var
Stream : TMemoryStream;
begin
Stream := TMemoryStream.Create;
CDS1.SaveToStream(Stream);
Stream.Position := 0;
TetheringAppProfile1.Resources.FindByName('BioLife').Value := Stream;
end;
客户端代码:
type
TFmxApp2Form = class(TForm)
CDS1: TClientDataSet;
DataSource1: TDataSource;
ImageControl1: TImageControl;
BindingsList1: TBindingsList;
BindNavigator1: TBindNavigator;
BindSourceDB1: TBindSourceDB;
LinkControlToField2: TLinkControlToField;
TetheringManager1: TTetheringManager;
TetheringAppProfile1: TTetheringAppProfile;
StringGrid1: TStringGrid;
Label1: TLabel;
CDS1SpeciesNo: TFloatField;
CDS1Category: TStringField;
CDS1Common_Name: TStringField;
CDS1SpeciesName: TStringField;
CDS1Lengthcm: TFloatField;
CDS1Length_In: TFloatField;
CDS1Notes: TMemoField;
CDS1Graphic: TGraphicField;
LinkGridToDataSource1: TLinkGridToDataSource;
procedure TetheringAppProfile1ResourceReceived(const Sender: TObject; const
AResource: TRemoteResource);
procedure TetheringManager1PairedFromLocal(const Sender: TObject; const
AManagerInfo: TTetheringManagerInfo);
private
end;
[...]
procedure TFmxApp2Form.TetheringAppProfile1ResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
begin
AResource.Value.AsStream.Position := 0;
CDS1.LoadFromStream(AResource.Value.AsStream);
end;
procedure TFmxApp2Form.TetheringManager1PairedFromLocal(const Sender: TObject; const
AManagerInfo: TTetheringManagerInfo);
begin
Label1.Text := Format('Connected : %s %s',
[AManagerInfo.ManagerIdentifier,
AManagerInfo.ManagerName]);
end;
客户端DFM
object FmxApp2Form: TFmxApp2Form
[...]
object ImageControl1: TImageControl
Bitmap.PNG = {}
object BindNavigator1: TBindNavigator
[...]
DataSource = BindSourceDB1
end
object StringGrid1: TStringGrid
[...]
end
object Label1: TLabel
[...]
end
object CDS1: TClientDataSet
Aggregates = <>
FieldDefs = <
item
Name = 'Species No'
DataType = ftFloat
end
item
Name = 'Category'
DataType = ftString
Size = 15
end
item
Name = 'Common_Name'
DataType = ftString
Size = 30
end
item
Name = 'Species Name'
DataType = ftString
Size = 40
end
item
Name = 'Length (cm)'
DataType = ftFloat
end
item
Name = 'Length_In'
DataType = ftFloat
end
item
Name = 'Notes'
DataType = ftMemo
Size = 50
end
item
Name = 'Graphic'
DataType = ftGraphic
end>
IndexDefs = <>
Params = <>
StoreDefs = True
Left = 40
Top = 32
object CDS1SpeciesNo: TFloatField
FieldName = 'Species No'
end
object CDS1Category: TStringField
FieldName = 'Category'
Size = 15
end
object CDS1Common_Name: TStringField
FieldName = 'Common_Name'
Size = 30
end
object CDS1SpeciesName: TStringField
FieldName = 'Species Name'
Size = 40
end
object CDS1Lengthcm: TFloatField
FieldName = 'Length (cm)'
end
object CDS1Length_In: TFloatField
FieldName = 'Length_In'
end
object CDS1Notes: TMemoField
FieldName = 'Notes'
BlobType = ftMemo
Size = 50
end
object CDS1Graphic: TGraphicField
FieldName = 'Graphic'
BlobType = ftGraphic
end
end
object DataSource1: TDataSource
DataSet = CDS1
Left = 104
Top = 32
end
object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
Left = 40
Top = 152
object LinkControlToField2: TLinkControlToField
Category = 'Quick Bindings'
DataSource = BindSourceDB1
FieldName = 'Graphic'
Control = ImageControl1
Track = False
end
object LinkGridToDataSource1: TLinkGridToDataSource
Category = 'Quick Bindings'
DataSource = BindSourceDB1
GridControl = StringGrid1
Columns = <>
end
end
object BindSourceDB1: TBindSourceDB
DataSet = CDS1
ScopeMappings = <>
Left = 40
Top = 88
end
object TetheringManager1: TTetheringManager
OnPairedFromLocal = TetheringManager1PairedFromLocal
Text = 'TetheringManager1'
AllowedAdapters = 'Network'
Left = 40
Top = 240
end
object TetheringAppProfile1: TTetheringAppProfile
Manager = TetheringManager1
Text = 'TetheringAppProfile1'
Group = 'MAGroup'
Actions = <>
Resources = <
item
Name = 'BioLife'
IsPublic = True
Kind = Mirror
ResType = Stream
OnResourceReceived = TetheringAppProfile1ResourceReceived
end>
OnResourceReceived = TetheringAppProfile1ResourceReceived
Left = 224
Top = 240
end
end
TClientDataSets似乎可以在LiveBindings中正常工作,因此如果您仍然遇到问题,可能会像我一样使用数据传输。
TClientDataSets seem to work fine with LiveBindings, so if you are still having problems, it might be worth doing the data transfer in the same way as I have.
对于您的第二个q
如何从服务器数据库复制所有图像并保存在客户端创建的文件夹[客户端\db\images]?
How to copy all Images From Server Database and save on Client Created folder[Client\db\images] ?
如果您使用TClientDataSet来保存客户端上的数据(即使您正在显示它)使用一些LiveBindings机制),您可以通过调用CDS的 SaveToFile
方法将其保存在客户端。
If you use a TClientDataSet to hold the data on your client (even if you are displaying it using some LiveBindings mechanism), you can save it on the client simply by calling the CDS's SaveToFile
method.
这篇关于Delphi:如何通过使用应用程序绑定从服务器数据库获取所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!