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

aradeonas aradeonas at operamail.com
Fri Mar 13 17:50:31 CET 2015


Thanks Martin. Graeme I tested your way but you cant get property values
with this way,if you test code that I sent before showmessage will show
nothing. but writeln will work.
>
> { IFile }
>
> IFile = interface function GetName: string; procedure SetName(AValue:
> string); property Name: string read GetName write SetName; end;
>
> TFileList=specialize TFPGList<IFile>;
>
>
> { TVideoFile }
>
> TVideoFile = class(TInterfacedPersistent, IFile) private FName:
> string; FWidth: integer; function GetName: string; procedure
> SetName(AValue: string); public property Name: string read GetName
> write SetName; property Width: integer read FWidth write FWidth; end;
> { TAudioFile }
>
> TAudioFile = class(TInterfacedPersistent, IFile) private FName:
> string; FArtist: string; function GetName: string; procedure
> SetName(AValue: string); public property Name: string read
> GetName write SetName; property Artist: string read FArtist write
> FArtist; end;
>
> var Form1: TForm1;
>
> implementation
>
> {$R *.lfm}
>
> { TAudioFile }
>
> function TAudioFile.GetName: string; begin Result:=FName; end;
>
> procedure TAudioFile.SetName(AValue: string); begin
> FName:=AValue; end;
>
> { TVideoFile }
>
> function TVideoFile.GetName: string; begin Result:=FName; end;
>
> procedure TVideoFile.SetName(AValue: string); begin
> FName:=AValue; end;

> var V1,V2:TVideoFile; A1,A2:TAudioFile; Fl:TFileList; begin
> Fl:=TFileList.Create; V1:=TVideoFile.Create; V1.Name:='V';
> V1.Width:=100;
> A1:=TAudioFile.Create;
> A1.Name:='A';
> A1.Artist:='Art'; FL.Add(V1); FL.Add(A1); V2:=TVideoFile(FL.Items[0]);
> A2:=TAudioFile(Fl.Items[1]); ShowMessage(V2.Name);
>    ShowMessage(A2.Name); end;
>

Regards, Ara



-- 
http://www.fastmail.com - Access all of your messages and folders
                          wherever you are

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150313/9f54a84a/attachment-0003.html>


More information about the Lazarus mailing list