delphi7找不到TBDEClientDataSet控件的解决方案

2008-04-09 04:22:18来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

unit BDEClientDataSet;

interface

uses Windows, SysUtils, Variants, Classes, DB, DBCommon, Midas,
SqlTimSt, DBClient, DBLocal, Provider, DBTables;


type
{ TBDEQuery }

TBDEQuery = class(TQuery)
private
FKeyFields: string;
protected
function PSGetDefaultOrder: TIndexDef; override;
end;

{ TBDEClientDataSet }
TBDEClientDataSet = class(TCustomCachedDataSet)
private
FCommandText: string;
FCurrentCommand: string;
FDataSet: TBDEQuery;
FDatabase: TDataBase;
FLocalParams: TParams;
FStreamedActive: Boolean;
procedure CheckMasterSourceActive(MasterSource: TDataSource);
procedure SetDetailsActive(Value: Boolean);
function GetConnection: TDataBase;
function GetDataSet: TDataSet;
function GetMasterSource: TDataSource;
function GetMasterFields: string;
procedure SetConnection(Value: TDataBase);
procedure SetDataSource(Value: TDataSource);
procedure SetLocalParams;
procedure SetMasterFields(const Value: string);
procedure SetParamsFromSQL(const Value: string);
procedure SetSQL(const Value: string);
protected
function GetCommandText: String; override;
procedure Loaded; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetActive(Value: Boolean); override;
procedure SetCommandText(Value: string); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure CloneCursor(Source: TCustomClientDataSet; Reset: Boolean;
KeepSettings: Boolean = False); override;
procedure GetFieldNames(List: TStrings); override;
function GetQuoteChar: String;
property DataSet: TDataSet read GetDataSet;
published
property Active;
property CommandText: string read GetCommandText write SetCommandText;
property DBConnection: TDataBase read GetConnection write SetConnection;
property MasterFields read GetMasterFields write SetMasterFields;
property MasterSource: TDataSource read GetMasterSource write SetDataSource;
end;

procedure Register;

implementation

uses BDEConst, MidConst;

type

{ TBDECDSParams }

TBDECDSParams = class(TParams)
private
FFieldName: TStrings;
protected
procedure ParseSelect(SQL: string);
public
constructor Create(Owner: TPersistent);
Destructor Destroy; override;
end;

constructor TBDECDSParams.Create(Owner: TPersistent);
begin
inherited;
FFieldName := TStringList.Create;
end;

destructor TBDECDSParams.Destroy;
begin
FreeAndNil(FFieldName);
inherited;
end;

procedure TBDECDSParams.ParseSelect(SQL: string);
const
SSelect = ''''select'''';
var
FWhereFound: Boolean;
Start: PChar;
FName, Value: string;
SQLToken, CurSection, LastToken: TSQLToken;
Params: Integer;
begin
if Pos('''' '''' SSelect '''' '''', LowerCase(string(PChar(SQL) 8))) > 1 then Exit; // can''''t parse sub queries
Start := PChar(ParseSQL(PChar(SQL), True));
CurSection := stUnknown;
LastToken := stUnknown;
FWhereFound := False;
Params := 0;
repeat
repeat
SQLToken := NextSQLToken(Start, FName, CurSection);
if SQLToken in [stWhere] then
begin
FWhereFound := True;
LastToken := stWhere;
end else if SQLToken in [stTableName] then
begin
{ Check for owner qualified table name }
if Start^ = ''''.'''' then
NextSQLToken(Start, FName, CurSection);
end else
if (SQLToken = stValue) and (LastToken = stWhere) then
SQLToken := stFieldName;
if SQLToken in SQLSections then CurSection := SQLToken;
until SQLToken in [stFieldName, stEnd];
if FWhereFound and (SQLToken in [stFieldName]) then
repeat
SQLToken := NextSQLToken(Start, Value, CurSection);
if SQLToken in SQLSections then CurSection := SQLToken;
until SQLToken in [stEnd,stValue,stIsNull,stIsNotNull,stFieldName];
if Value=''''?'''' then
begin
FFieldName.Add(FName);
Inc(Params);
end;
until (Params = Count) or (SQLToken in [stEnd]);
end;

{ TBDEQuery }

function TBDEQuery.PSGetDefaultOrder: TIndexDef;
begin
if FKeyFields = '''''''' then
Result := inherited PSGetDefaultOrder
else
begin // detail table default order
Result := TIndexDef.Create(nil);
Result.Options := [ixUnique]; // keyfield is unique
Result.Name := StringReplace(FKeyFields, '''';'''', ''''_'''', [rfReplaceAll]);
Result.Fields := FKeyFields;
end;
end;

{ TBDEClientDataSet }

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:创建快捷方式到[启动]

下一篇:一个读取速度超快的FileStream!