[Lazarus] How to cast a Interface to a Object in Lazaeus

Anthony Walter sysrpl at gmail.com
Fri Mar 13 16:00:04 CET 2015


I'm not sure if this point has been made already, but interface cast (or
querying as defined by COM), only works if the interface has a GUID
assigned. When this is the case, in delphi and I believe in {$mode delphi}
you can cast between object and interfaces like so:

procedure Test(Sender: TObject);
var
  A: IMyInterfaceType;
  B: TMyObjectType;
begin
  if Sender is IMyInterfaceType then
    A := Sender as IMyInterfaceType;
  if A is TMyObjectType then
    B := A as TMyObjectType;
  // other code here
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150313/677953c4/attachment-0003.html>


More information about the Lazarus mailing list