DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: power71483
今日帖子: 16
在线用户: 10
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/23 11:43:28
标题:
livebinding不稳定 浏览:1365
加入我的收藏
楼主: 1、一个窗口上面有若干组件,一个数据模块上有数据集,uses数据模块,现在将窗口上的组件livebind到数据模块上的数据集,如果是stringgrid正常,如果是edit、combobox、comboedit这些组件,获取数据正常,更新时不能保存数据。
2、删除livebinding设计器里的数据字段与组件的连线,发现删除连线后依然存在组件可以从数据集获取数据的情况。删除窗口上的组件会出灾难性事故。
3、删除livebinding时自动产生的那些连接组件,再删除组件时不会出错,改用手动数据更新,发现获取数据时行为异常。似乎livebinding对窗口做了一些无法考察的操作。
4、编译为win时正常些,编译为linux错误多些。
看来livebinding经历了10年的发展,仍然是不可靠的。
----------------------------------------------
-
作者:
男 roadrunner (roadrunner) ★☆☆☆☆ -
盒子活跃会员
2022/5/23 12:02:10
1楼: 没发现你所说的情况,你是怎么操作的发图说明一下
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/5/23 12:05:32
2楼: 在 Edit 里面更新了数据,数据没有保存到 DataSet 里面去,是因为有个设置你没做。具体是哪个属性我忘记了。你自己看看。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/5/23 12:08:43
3楼: 我的文章,结尾部分有提到更新的问题:

https://blog.csdn.net/pcplayer/article/details/104272700
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/5/23 12:10:45
4楼: 我的这篇文章,也提到更新数据的问题:

https://blog.csdn.net/pcplayer/article/details/69237885

【如果在界面修改了值,要将修改返回到对象,必须调用 AdapterBindSource1.ApplyUpdates 方法;如果程序给对象的属性字段修改了值,要反映到界面上,需要调用 AdapterBindSource1.Refresh.】
----------------------------------------------
-
作者:
男 zhoutler (苦行僧) ★☆☆☆☆ -
普通会员
2022/5/23 17:46:35
6楼: 可能是你的用深度太深了,我浅度使用livebindings,单向,双向绑定都没有问题,绑定表达式函数用起来也很不错。你注意看看你的窗体文件是否有错误的继承分类,我遇到过这种莫名其妙的问题,去掉就可以了。
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/24 8:16:30
7楼: 现在就是我删除frame上所有数据绑定,但似乎整个frame接收数据行为异常了。
我现在需要在此frame上弹出一个窗口,这个窗口绑定一个dataset和grid,这个绑定可以正常工作,在关闭窗口时读取改变dataset的数据,结果仍然是之前的数据。打开查看数据库,数据已经改变了,百思不得其解。
//在frame上创建弹出窗口,此frame删除过原来建立的livebinding
procedure TFrSystemSet.SpeedButton1Click(Sender: TObject);
begin
   AForm.DisposeOf;   //linux不能用freeandnil
   AForm:=nil;
   AForm:=TFMShowBalance.Create(self);
   AForm.ShowModal;
end;
//弹出窗口上将stringgrid绑定一个表,关闭时保存数据,可正常更新
procedure TFMShowBalance.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   BindSourceDB1.DataSet.Edit;
   BindSourceDB1.DataSet.Post;
end;
//用FDQYear打开被更新的表,但数据依然没更新,其实数据库表里数据已经更新了。
procedure TFrSystemSet.ComboEdit2Change(Sender: TObject);
begin
   FDQYear.Close;
   FDQYear.Open;//FDQYear.Refresh
   ComboEdit2.Items.Clear;
   FDQYear.First;
   while not FDQYear.Eof  do begin
     ComboEdit2.Items.Add(FDQYear.FieldByName('year').AsString);
     FDQYear.Next;
   end;
end;
我现在把 TFrSystemSet从工程里先移除再试试。
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/5/24 10:51:40
8楼: to apply updates automatically, just "BindSourceDB1.Datasource.AutoEdit=true" as normal Dataset!

then, when moving to next record, for example, the post will be done!
the rest, you need works with "TRANSACTION" (automatically or manual), then, you can "COMMIT" or not when you need.

For example, in FDConnection you have "TxOptions.AutoCommit = true/false.. AutoStart...AutoStop... etc..."

I think that it's a error "your", using "ComboEditOnChange" to "close/open" a Query all time! I dont want to talk about your use of "While... EOF" to fill it"

it's not necessary use "While EOF" (old times...) to fill the combobox! Just bind this component with a field in your table! this is right way!

if you need a "filter" in your record, you can have another Query with a SQL select to filter your record!
Ex; Select distincts Names from MyTable

if you need all time have a "FORM" to show your data, you dont need "CLOSE/KILL it"...."CREATE"
you can just "HIDE it", then, it always will be ready to use, include you dont need remove your "livebind links", because the form is "hide".
you see me?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/5/24 10:56:27
9楼:   // CHANGE THIS....
   AForm.DisposeOf;   //linux不能用freeandnil
   AForm:=nil;
   AForm:=TFMShowBalance.Create(self);
   AForm.ShowModal;
----------
   // USE THIS
... AForm.HIDE;

... AForm.Show/ShowModal;

when you need close your app, or table or DB, then, "AForm.Free" just one time!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/5/24 10:58:18
10楼: 您的数据搞砸了,可能是因为您在表单的相同组件中使用了“LiveBinding”和“WHILE TB.EOF”。
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/24 12:35:44
11楼: 谢谢,即使我把ComboEdit的itemtext绑定到数据集,不使用while tb.eof手动赋值,也不行,仍然不会更新数据。再说,我没有在同一界面混用livebinding和手动存取数据。
我只能重新打开frame后(这个frame是动态创建的),才能正常从数据库获取数据
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/24 12:39:21
12楼: 现在基本可以这样肯定,livebinding仍然是不成熟的。
livebinding获取数据没什么问题,但如果用livebinding更新了数据,数据会正常更新到物理数据库,但fmx的一些组件获取用livebinding更新的数据,无论是手动获取,还是用livebinging获取,肯定会有问题。
如要保证获取数据没有问题,只有老老实实用手动方法更新到数据库,别用livebinding。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/5/24 13:01:53
13楼: 看你的描述,是数据库里面的数据已经更新了,用 FdQuery 获取的数据没有获取到新的数据。

这个,你确定?
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/24 13:03:01
14楼: 是的。这个真的很难理解。
需要获取数据的窗口是一个动态创建的frame,明明数据已经更新了,但就是不能获取最新数据。只能重新创建frame进入界面,此时数据才是最新的。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/5/24 13:12:43
15楼: 如果确定数据库已经有新数据了,FdQuery 没理由无法获得数据。

这个和 LiveBinding 无关;

通常,出现这种莫名其妙的奇怪问题,不要去怪 Delphi,先看看自己哪里没做对。
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/24 16:22:35
16楼: 楼上所言极是,再次证明如果出现错误,99.99%不能怪delphi
问题发生在comboedit的onchange事件里,改成这样就正常了
procedure TFrSystemSet.ComboBox2Enter(Sender: TObject);
begin
   FDQYear.Refresh;
   ComboBox2.Items.Clear;
   FDQYear.First;
   while not FDQYear.Eof  do begin
     ComboBox2.Items.Add(FDQYear.FieldByName('year').AsString);
     FDQYear.Next;
   end;
   ComboBox2.DropDownKind := TDropDownKind.Custom;     //改变下拉字体大小
   for var I := 0 to ComboBox2.Items.Count-1 do   begin
      ComboBox2.ListBox.ListItems[i].StyledSettings:=[];
      ComboBox2.ListBox.ListItems[i].TextSettings.Font.Size := 14;
      ComboBox2.ListBox.ListItems[i].Height := 25;
   end;
end;
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/5/24 22:04:45
17楼: 谁不想学,就忽略一条建议! 即使这个建议现在对你来说不是最好的!

who does not want to learn, just ignore a piece of advice! Even if this advice is not the best for you right now!

我认为这位同事犯了基本错误,将当前技术与旧的编程方法混合在一起!
但选择是他的,不是我的。 所以这次我闭嘴!

I think the colleague is making basic mistakes, mixing current techniques with old programming methods!
But the choice is his, not mine. So I'll shut up this time!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/25 18:55:37
18楼: 巴西大师,反正我的办法管用。
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行1882.813毫秒 RSS