About DBGridEh DrawColumnEhCell Error

When used DBGridEh in a script form, than called the DrawColumnEhCell even,got an error message. 

  Exception class EInvalidCast with message 'Invalid class typecast'.


//  The Script is very easy:

procedure DBGridEh1DrawColumnCell(Sender: TObject; Rect: TRect; DataCol: Integer;
 Column: TColumnEh; State: TGridDrawState);
begin
 if ((DBGridEh1.DataSource.Dataset.FieldByName('ItemNo').AsInteger mod 2) =0) then
  begin                                                    
   DBGridEh1.Canvas.Font.Color := clYellow;                            
   DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);    // error here
  end;                                                           
end; 


//----------------------------------------------------------------------------------------------------- 
// register code:


procedure TatDBGridEhDispatcher.__TDrawColumnEhCellEvent( Sender: TObject; const Rect: TRect;  DataCol: Integer;  Column: TColumnEh;  State: TGridDrawState);
var
  StateTempSet: TGridDrawState;
  StateTemp: variant;
  ColumnTemp:Variant;
  RectTemp:TRectWrapper;
begin
  if DoOnExecuteEvent then
  begin
    if AssignedMethod(BeforeCall) then
      TDrawColumnEhCellEvent(BeforeCall)(Sender,Rect,DataCol,Column,State);
    StateTempSet := State;
    StateTemp := IntFromSet(StateTempSet, SizeOf(StateTempSet));
    RectTemp:=  TRectWrapper.Create(Rect);
    ColumnTemp:= ObjectToVar(Column) ;
    if Assigned(Scripter) and (RoutineName > '') then
      Scripter.ExecuteSubroutine(RoutineName, [Sender,RectTemp,DataCol,ColumnTemp,StateTemp]);
    RectTemp.Free;
    if AssignedMethod(AfterCall) then
      TDrawColumnEhCellEvent(AfterCall)(Sender,Rect,DataCol,Column,State);
  end;
end;

Where did I make a mistake?

Best regards.

Hi, What is the exactly line that raises that error?

Error messages:
//-------------------------------------------------------
First chance exception at $74C1AA12. Exception class EatScripterRuntime with message
'RUNTIME ERROR
File library uScriptForm: Invalid class typecast when evaluating instruction CallProc ($FFFFFFFF,$4,$6E0818,$3ED0B60,'DefaultDrawColumnCell').
Stack content is: [Integer:5,Integer:52272496,Integer:0,Integer:138620616...].
Source position: 170,65
Position: 170, 65'.
Process ClientX.exe (6808)
//---------------------------------------------------------------------

//  The Script:

procedure DBGridEh1DrawColumnCell(Sender: TObject; Rect: TRect; DataCol: Integer;
 Column: TColumnEh; State: TGridDrawState);
begin
 if ((DBGridEh1.DataSource.Dataset.FieldByName('ItemNo').AsInteger mod 2) =0) then
  begin                                                    
   DBGridEh1.Canvas.Font.Color := clYellow;                            
   DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);    // error here
  end;                                                           
end; 

Ok, but still if you are debugging your application in debug mode (preferably using debug dcu's) the call stack at the moment of the error will indicate the exact line of the source code (together with call stack itself) where the error happened. You only mentioned the scripter error message, and the line in script that raised the error, but that script line is calling a Delphi method which in turn is calling Delphi code. It's inside that Delphi code that I'd like to see what's going on.


What is the relation of DefaultDrawColumnCell with __TDrawColumnEhCellEvent, for example?
I found the cause of the mistake. Because both DBGrid and DBGridEh have DefaultDrawColumnCell functions, the definitions between the two are different.
TIDEDialog register TDBGrid by Default.

// The DBGrid definition :
procedure DefaultDrawColumnCell(const Rect: TRect; DataCol: Integer;
      Column: TColumn; State: TGridDrawState);

// The DBGridEh definition :
procedure DefaultDrawColumnCell(const Rect: TRect; DataCol: Integer; 
      Column: TColumnEh; State: TGridDrawState);

The Column param is diffrent,  That is it.

Thanks for the reply.