DELPHI 2010 中的 BDE 到 ADO 转换

发布于 2024-09-08 05:38:56 字数 1036 浏览 2 评论 0原文

我正在为我的公司将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾铮苏瑾 2024-09-15 05:38:56

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 new TQuery 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 of with 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 that with block is Eof, 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.

倾听心声的旋律 2024-09-15 05:38:56

您尝试将 TQuery 更改为 TADOQuery,然后会发生什么?

You tried changing the TQuery to a TADOQuery, and then what happens?

清风疏影 2024-09-15 05:38:56

IMO,你应该使用 try..finally..free..end;
否则,您将创建一个查询并且永远不会释放它。
即第2行应该是“尝试”。

with Tquery.Create(nil) do 
try
  ..  
  ..  
finally
  free;
end; 

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".

with Tquery.Create(nil) do 
try
  ..  
  ..  
finally
  free;
end; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文