PAS:
Code: Select all
unit SDACTestU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, MemDS, VirtualTable, DBAccess, MSAccess, ExtCtrls;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
EinkaufQ: TMSQuery;
MSConnection1: TMSConnection;
EinkaufQbez: TStringField;
EinkaufQStaffelPreisVorhanden: TSmallintField;
Timer1: TTimer;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (Column.Field = EinkaufQStaffelPreisVorhanden) and EinkaufQStaffelPreisVorhanden.IsNull then begin
if not (EinkaufQ.State in [dsEdit, dsInsert]) then
EinkaufQ.Edit;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EinkaufQ.Open;
EinkaufQ.DisableControls;
EinkaufQ.Append;
EinkaufQBez.AsString := '423423423';
EinkaufQ.Post;
EinkaufQ.Append;
EinkaufQBez.AsString := '423423423';
EinkaufQ.Post;
EinkaufQ.EnableControls;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
EinkaufQ.Prior;
EinkaufQ.Next;
end;
end.
Code: Select all
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 333
ClientWidth = 676
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 80
Top = 40
Width = 409
Height = 120
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
OnDrawColumnCell = DBGrid1DrawColumnCell
Columns =
end
object DataSource1: TDataSource
DataSet = EinkaufQ
Left = 256
Top = 176
end
object EinkaufQ: TMSQuery
Connection = MSConnection1
SQL.Strings = (
'select cast(null as varchar(255)) as bez, cast(null as smallint)' +
' as StaffelPreisVorhanden')
CachedUpdates = True
Left = 320
Top = 240
object EinkaufQbez: TStringField
FieldName = 'bez'
FixedChar = True
Size = 80
end
object EinkaufQStaffelPreisVorhanden: TSmallintField
FieldName = 'StaffelPreisVorhanden'
ReadOnly = True
end
end
object MSConnection1: TMSConnection
Database = 'doma'
Username = 'sa'
Server = 'DELO'
Connected = True
Left = 256
Top = 240
end
object Timer1: TTimer
OnTimer = Timer1Timer
Left = 416
Top = 216
end
end
It's probably because of the editing in the drawcolumncell event - but i think, it should not fail so late and with such really hard-to-identify exception (i spent hours identifying it and creating this example , i have also seen disposebuf failed, some FastMM warnings, etc. )
please, could you provide a correction? or, if the editing in drawcolumncell event is not possible, make some human-readable error message directly at the ".edit" command?
thanks much, ludek.