I never needed to use interfaces on my code, but now I got a situation
where I think it will be usefull... Let me explain what I got:
I've created a tree structure (it's a lazy load structure...) to hold
some huge binary data... Each item on this tree shares a TFileStream
object... These items have fields like FDataBegin, FDataLength, etc...
Since the TStream is shared, any of these items can't free the TStream
if there's someone using it... I was going to implement a reference
count on my class or maybe create a "TTree" which would hold
"TTreeNodes" and it would be able to free the TStream, but then I
remembered of Interfaces =]
I took a look on the help about interfaces, and I've made the
following code based on that TInterfacedObject...
TInterfacedStream = class( TFileStream, IInterface )
private
FRefCount: Integer;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
class function NewInstance: TObject; override;
property RefCount: Integer read FRefCount;
end;
But after testing I see the Interface isn't auto-freeing :)
So... Am I doing it right haha?
--
"ME ALIMENTE [http://br-linux.org/noticias/002750.html] hehe"
"Invente, Tente!!! Fa�a um c�digo eficiente" (Jonas Raoni haha)
Jonas Raoni Soares Silva
---------------------------
Desenvolvedor de aplica��es
jonasraoni at gmail dot com
http://www.joninhas.ath.cx:666
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/