🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #37

typecasting interfaces

#37
From: Maurizio Ferreira
Date: Thu, 30 Jun 2005 08:51
44 lines
1781 bytes
I have a series of frames, each implementing a common interface

type
  ImyInterf = interface
    procedure doit;
  end;

  tframe1 = class (tframe,ImyInterf)
   ....
   procedure doit;
  end;

  tframe2 = class (tframe,ImyInterf)
   ....
   procedure doit;
  end;

Now I'd like to iterate on the form components to activate every frame
:

procedure  TMainForm.ActivateFrame;
var   I : integer;
      F : ImyInterf;
begin
  for I := 0 to ComponentCount -1 do begin
    if Components[i] is tFrame then begin
      F := Components[i] as ImyInterf;   // ---- Error
      F := ImyInterf(Components[i]);     // ---- Error
      F.doit;  // --- this is what i'd like to call
    end;
  end;
end;

However The compiler (d7) complains in the above statements:

The first gives the error:
  operator not applicable to this operand type

the second the error
  incompatible types ImyInterf and tcomponent

What can I do ?
Regards
Maurizio
Technical Details
Message-ID: <1ob7c15f14llkd5g8iup0d5fqpe9igt23d@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!ilaria.aioe.org!aioe.org!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 109d30,8f058075853262b4,start
X-Google-Attributes: gid109d30,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!ilaria.aioe.org!aioe.org!not-for-mail
From: Maurizio Ferreira <maurizio.ferreira@selesta.it>
Newsgroups: borland.public.delphi.language.objectpascal
Subject: typecasting interfaces
Date: Thu, 30 Jun 2005 10:51:58 +0200
Organization: Aioe.org NNTP Server
Lines: 46
Message-ID: <1ob7c15f14llkd5g8iup0d5fqpe9igt23d@4ax.com>
NNTP-Posting-Host: buSqxRrR1IJZdDcvyzcubw.domitilla.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
NNTP-Posting-Date: Thu, 30 Jun 2005 08:49:49 +0000 (UTC)
X-Newsreader: Forte Free Agent 1.92/32.572