使用dbExpress时出现内存问题

时间:2019-06-21 13:21:29

标签: delphi delphi-7 dbexpress

我必须在旧版Delphi 7应用程序上做一些工作,想从ADO组件切换到dbExpress,但这给我带来了一个奇怪的问题。

设置很简单
当我使用ADO时,我拥有

ADOConnection
ADOQuery

DataSetProvider
ClientDataSet
DataSource
DBGrid

执行返回约50000行的查询时,没有问题。
我可以滚动到最后一行,没有问题

现在,当我使用dbExpress时,我具有以下设置。
请注意,我只切换了前2个组件,其他所有组件均保持不变。

SQLConnection
SQLQuery

DataSetProvider
ClientDataSet
DataSource
DBGrid

执行相同的查询有效,并且打开速度更快。
但是我再也无法滚动到最后一行,如果尝试这样做,我会得到错误

  

该操作的内存不足

在两种情况下,我都使用完全相同的代码

ClientDataSet1.Open;

没有任何事件与任何组件相关。
实际上,我做了一个小的测试项目,除了这些组件之外什么也没有,它仍然给出相同的错误。因此它易于复制。

使用ADO时ClientDataSet如何能够容纳所有50000行,而使用dbExpress时却不能容纳全部50000行?
我该如何解决?

根据要求,这是示例项目的完整代码(我省略了持久字段,以使其更小)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBClient, Provider, ADODB, StdCtrls, DBCtrls, Grids,
  DBGrids, ExtCtrls, DBXpress, FMTBcd, SqlExpr;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    Button1: TButton;
    Button2: TButton;
    DataSetProvider1: TDataSetProvider;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    Label1: TLabel;
    SQLConnection1: TSQLConnection;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ClientDataSet1.Open;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ClientDataSet1.Close;
end;

end.

还有DFM(我省略了持久字段以使其更小)

object Form1: TForm1
  Left = 347
  Top = 125
  Width = 1305
  Height = 675
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 1289
    Height = 97
    Align = alTop
    Caption = 'Panel1'
    TabOrder = 0
    object Label1: TLabel
      Left = 240
      Top = 32
      Width = 32
      Height = 13
      Caption = 'Label1'
    end
    object DBNavigator1: TDBNavigator
      Left = 16
      Top = 64
      Width = 240
      Height = 25
      DataSource = DataSource1
      TabOrder = 0
    end
    object Button1: TButton
      Left = 32
      Top = 24
      Width = 75
      Height = 25
      Caption = 'connect'
      TabOrder = 1
      OnClick = Button1Click
    end
    object Button2: TButton
      Left = 112
      Top = 24
      Width = 75
      Height = 25
      Caption = 'disconnect'
      TabOrder = 2
      OnClick = Button2Click
    end
  end
  object DBGrid1: TDBGrid
    Left = 0
    Top = 97
    Width = 1289
    Height = 539
    Align = alClient
    DataSource = DataSource1
    TabOrder = 1
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object DataSetProvider1: TDataSetProvider
    DataSet = SQLQuery1
    Left = 512
    Top = 328
  end
  object ClientDataSet1: TClientDataSet
    Aggregates = <>
    PacketRecords = 50
    Params = <>
    ProviderName = 'DataSetProvider1'
    Left = 512
    Top = 392
  end
  object DataSource1: TDataSource
    DataSet = ClientDataSet1
    Left = 528
    Top = 456
  end
  object SQLConnection1: TSQLConnection
    ConnectionName = 'MSSQLConnection'
    DriverName = 'MSSQL'
    GetDriverFunc = 'getSQLDriverMSSQL'
    LibraryName = 'dbexpmss.dll'
    LoginPrompt = False
    Params.Strings = (
      'DriverName=MSSQL'
      'HostName=XXXXXX'
      'DataBase=GTT_Test'
      'User_Name=XXX'
      'Password=XXX'
      'BlobSize=-1'
      'ErrorResourceFile='
      'LocaleCode=0000'
      'MSSQL TransIsolation=ReadCommited'
      'OS Authentication=False')
    VendorLib = 'oledb'
    Left = 584
    Top = 208
  end
  object SQLQuery1: TSQLQuery
    MaxBlobSize = -1
    Params = <>
    SQL.Strings = (
      'select * from vwRitComplete')
    SQLConnection = SQLConnection1
    Left = 584
    Top = 272
  end
end

0 个答案:

没有答案