DELPHI 2010 中的 BDE 到 ADO 转换
我正在为我的公司将 BDE 转换为 ADO。我遇到了一个表达式,我无法弄清楚如何转换为 ADO
这是 BDE 表达式,其中包含除一个之外的所有 ADO 更改....导致我出现问题的部分是
使用 Tquery.Create(nil) 执行的操作一开始。有什么想法吗?
with Tquery.Create(nil) do
begin
cmd := TStringList.Create;
cmd.Add('select top 3 csnttext from casenotesint');
cmd.Add('where csntcaseid = ''' + scasenum + ''' ');
cmd.Add('and csntclmid = ''' + sclmnumber + ssplitcode + ''' ');
cmd.Add('order by csntseqnum desc');
rs := fConnection.Execute(cmd.Text);
cmd.Free;
while not Eof do
begin
SAPrintReport1.Tab(0.5);
SAPrintReport1.Print(rs.Fields.Item('CsNtText').Value);
SAPrintReport1.NewLine;
rs.next;
end;
rs.Close;
end;
if cbxSpacer.checked then
begin
SAPrintReport1.NewLine;
SAPrintReport1.NewLine;
SAPrintReport1.NewLine;
end;
I am working on converting BDE to ADO for my company. I have run into an expression I can not figure out how to convert to ADO
Here is the BDE expression with all the ADO changes except for one....the part that is causing me issues is the
with Tquery.Create(nil) do at the beginning. Any ideas?
with Tquery.Create(nil) do
begin
cmd := TStringList.Create;
cmd.Add('select top 3 csnttext from casenotesint');
cmd.Add('where csntcaseid = ''' + scasenum + ''' ');
cmd.Add('and csntclmid = ''' + sclmnumber + ssplitcode + ''' ');
cmd.Add('order by csntseqnum desc');
rs := fConnection.Execute(cmd.Text);
cmd.Free;
while not Eof do
begin
SAPrintReport1.Tab(0.5);
SAPrintReport1.Print(rs.Fields.Item('CsNtText').Value);
SAPrintReport1.NewLine;
rs.next;
end;
rs.Close;
end;
if cbxSpacer.checked then
begin
SAPrintReport1.NewLine;
SAPrintReport1.NewLine;
SAPrintReport1.NewLine;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
with
语句将给定对象的成员引入作用域,因此您可以提及其字段、方法和属性,而不必使用它们所属的对象的名称来限定它们。请参阅文档中的With 语句。可以放入
with
语句中的有效对象是刚刚新创建的对象。这里就是这种情况。该代码创建一个新的TQuery
对象并立即隐式使用其所有成员。对该对象的引用不存储在任何局部变量中,因此没有显式的方法来引用它,但这不会打扰编译器。 (不过,它可能会困扰人类,这也是人们不鼓励在 Delphi 中使用with
的原因之一。)不属于给定对象的标识符在而是下一个周围范围。看起来
with
块中使用的TQuery
的唯一标识符是Eof
,因此您要转换的代码无论如何都可能是错误的。最好只是弄清楚代码应该做什么,然后为此编写新的 ADO 代码。A
with
statement brings the given object's members into scope, so you can mention its fields, methods, and properties without having to qualify them with the name of the object they belong to. Please see With Statements in the documentation.One thing that's valid to put in a
with
statement is an object that was just newly created. That's the case here. The code creates a newTQuery
object and immediately uses all its members implicitly. The reference to that object is not stored in any local variable, so there's no explicitly way to refer to it, but that doesn't bother the compiler. (It can bother humans, though, which is one of the reasons you'll see for people to discourage use ofwith
in Delphi.)Identifiers that don't belong to the given object are searched for in the next surrounding scope instead. It looks like the only identifier from
TQuery
being used in thatwith
block isEof
, so the code you're converting is probably wrong anyway. It might be better to just figure out what the code was supposed to be doing, and then write new ADO code for that.您尝试将 TQuery 更改为 TADOQuery,然后会发生什么?
You tried changing the TQuery to a TADOQuery, and then what happens?
IMO,你应该使用 try..finally..free..end;
否则,您将创建一个查询并且永远不会释放它。
即第2行应该是“尝试”。
IMO, you should use try..finally..free..end;
Otherwise, you're creating a query and never freeing it.
i.e. line 2 should be "try".