[Lazarus] How to cast a Interface to a Object in Lazaeus
mailinglists at geldenhuys.co.uk
Fri Mar 13 11:16:39 CET 2015
On 2015-03-13 09:39, aradeonas wrote:
> About question you mean make a File class with name,size,artist,width
> and all others in one place?If this I didn't like it,It seem messy,
I agree, I wouldn't do it that way either. I would have subclasses which
gives more specific details of each media type.
TBaseFile = class(TObject)
property Name: string...
property Size: integer...
property Caption: string...
TVideoFile = class(TBaseFile)
property Width: integer...
TAudioFile = class(TBaseFile)
property Artist: string...
In your listview somewhere
obj can be a TBaseFile, TVideoFile or TAudioFile instance.
Then in your listview's OnPaint event (on whatever event draws each row)
obj := ListView.Items[Listview.Selected] as TBaseFile;
if obj is TAudioFile then
// do something with TAudioFile(obj).Artist etc.
else if obj is TVideoFile then
// do something with TVideoFile(obj).Width etc
else if obj is TBaseFile then
// do whatever
This is just one possible way of doing it. Interface can obviously also
be used in a similar way, where one interface descends from another.
- Graeme -
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
More information about the Lazarus