home *** CD-ROM | disk | FTP | other *** search
- {
- BUSINESS CONSULTING
- s a i n t - p e t e r s b u r g
-
- Components Library for Borland Delphi 4.x, 5.x
- Copyright (c) 1998-2000 Alex'EM
-
- }
- unit DCADOCtrl;
-
- interface
- {$I DCConst.inc}
-
- {$IFDEF DELPHI_V5UP}
-
- uses SysUtils, db, ADOdb, DCConst, DCChoice;
-
- type
- TDCADOGridEdit = class(TDCCustomGridEdit)
- private
- procedure SetParameters(const Value: TParameters);
- function GetParameters: TParameters;
- function GetConnection: TADOConnection;
- procedure SetConnection(const Value: TADOConnection);
- protected
- procedure SetInternalDataSet(const Value: TDataSet; var DataSet: TDataSet); override;
- procedure SetInternalSQLText(const Value: string; var SQLText: string); override;
- function CreateQuery: TDataSet; override;
- procedure DoInitQuery(Mode: integer); override;
- function GetQueryText: string; override;
- procedure PrepareDataSet; override;
- public
- property ButtonEnabled;
- published
- property DrawStyle;
- property CheckGlyph;
- property CheckTag;
- property ReadOnly;
- property Parameters: TParameters read GetParameters write SetParameters;
- property Connection: TADOConnection read GetConnection write SetConnection;
- property EditMask;
- end;
-
- {$ENDIF}
-
- implementation
- {$IFDEF DELPHI_V5UP}
-
- { TDCADOGridEdit }
- function TDCADOGridEdit.CreateQuery: TDataSet;
- begin
- Result := TADOQuery.Create(Self);
- end;
-
- procedure TDCADOGridEdit.DoInitQuery(Mode: integer);
- begin
- with TADOQuery(Query) do
- begin
- SQL.Text := GetPreparedQueryText(Mode, SQL.Text);
- Open;
- end;
- end;
-
- function TDCADOGridEdit.GetConnection: TADOConnection;
- begin
- Result := TADOQuery(Query).Connection;
- end;
-
- function TDCADOGridEdit.GetParameters: TParameters;
- begin
- Result := TADOQuery(Query).Parameters;
- end;
-
- function TDCADOGridEdit.GetQueryText: string;
- var
- i: integer;
- begin
- Result := '';
- for i := 0 to TADOQuery(Query).SQL.Count -1 do
- begin
- if Result <> '' then Result := Result+ #10;
- Result := Result + TADOQuery(Query).SQL.Strings[i];
- end;
- end;
-
- procedure TDCADOGridEdit.PrepareDataSet;
- var
- AParams: TParameters;
- begin
- AParams := TParameters.Create(Self, TParameter);
- try
- AParams.Assign(Parameters);
- with TADOQuery(Query) do
- begin
- Close;
- SQL.Clear;
- SQL.Text := SQLText;
- Parameters.Assign(AParams);
- end;
- finally
- AParams.Free;
- end;
- end;
-
- procedure TDCADOGridEdit.SetConnection(const Value: TADOConnection);
- begin
- TADOQuery(Query).Connection := Value;
- end;
-
- procedure TDCADOGridEdit.SetInternalDataSet(const Value: TDataSet; var DataSet: TDataSet);
- begin
- DataSet := Value;
- if Query.Active then Query.Close;
- if (DataSet is TADOQuery) and not ListBoxEnabled then
- SetSQLTextPermanet(TADOQuery(DataSet).SQL.Text)
- else
- if not QueryDataSet then SetSQLTextPermanet('');
-
- if not QueryDataSet then
- begin
- if (DataSet <> nil) and DataSet.Active then
- SetGridValues
- else
- Values.Clear;
- end
- end;
-
- procedure TDCADOGridEdit.SetInternalSQLText(const Value: string;
- var SQLText: string);
- begin
- if TADOQuery(Query).Active then TADOQuery(Query).Close;
- if Value <> '' then TADOQuery(Query).SQL.Text := SQLText;
- end;
-
- procedure TDCADOGridEdit.SetParameters(const Value: TParameters);
- begin
- TADOQuery(Query).Parameters.AssignValues(Value);
- end;
-
- {$ENDIF}
-
- end.
-