[Lazarus] Delphi incompatibility - hard cast

Bob Hofman oldtimer.tools at gmail.com
Sat Jan 18 03:55:25 CET 2014

Depending on what the Sender is it might work if it can be cast to a
TDBGrid. Can you actually run an application with that cast? What is the

I put a DBGrid and a DBMemo on a form and in the OnShow assigned the
DataSource property of each to a DataSource I had also placed on the form.
Everything worked as expected. Then I changed the assignment to the DBMemo
to the following:

TDBGrid(DBMemo1).DataSource := DataSource1;

Both a syntax check and a build did not throw any errors but if I attempted
to run the application it would error out with an access violation as soon
as it got to the above assignment.

I think that FPC is just catching it at compile time while Delphi is not.


On Fri, Jan 17, 2014 at 8:44 PM, Hans-Peter Diettrich
<DrDiettrich1 at aol.com>wrote:

> Alejandro Gonzalo schrieb:
>  In Delphi this will work even if the Sender is not a TdbGrid, as long as
>> it has a DataSource property:
> It only *happens* to work for you in Delphi.
>    TdbGrid(Sender).datasource:=myDataSource;
> This hack requires that Sender has a DataSource property in *exactly* the
> same place where it sits in TdbGrid. That's very unlikely for any other
> class.
> DoDi
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140117/ed644fc4/attachment-0003.html>

More information about the Lazarus mailing list