Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with TMemoryStream

Status
Not open for further replies.

simmo09

Programmer
Apr 22, 2009
82
GB
Hi, here is a quick introduction to what im trying to do:

load sounds (midi,mp3,wav) into a memory stream, then when called determine from the memory stream what type of file it is and play it.

im not a expert coder and am always keen to learn, code samples is easiest way for me to do this. searching for ages on the net i found this:

Code:
procedure LoadFromFileToMemory(const AFilename: String; memStream: TMemoryStream);
var
  aFileStream: TFileStream;
begin
  aFileStream:= TFileStream.Create(AFilename, fmOpenRead);
  try
   memStream.CopyFrom(aFileStream, 0);
  finally
   aFileStream.Free;
  end;
end;

{
  LoadFromFileToMemory usage example
  **********************************

  var
    memStream: TMemoryStream;

    memStream:= TMemoryStream.Create;
    try
      LoadFromFileToMemory('C\my file.mp3',memStream);
    finally
      memStream.Free;
    end;
  end;
}

i can identify the file extension if i wanted by using ExtractFileExt('C\my file.mp3'), but if the file is in memory how could i do it?

Thanks
 
very informative thank you, will get to this once i figure the basics, i have had an attempt at changing the attachment i posted, but to no avail, im not even sure if im declaring things right, and do i still need the array?

Code:
type
  TSoundItem = [b]class(TObject)[/b]
    FileName: String;
    FileExtension: String;
    Loop: Boolean;
    Volume: Integer;
  end;
 
You need an objeclist. (look in the help file for the contnrs unit).

what I would do is expand your object and put in some methods related to the object.

so you got a TSoundItem:

Code:
  TSoundItem = class(TObject)    
  public
   FileName: String;    
   FileExtension: String;    
   Loop: Boolean;    
   Volume: Integer;  
   procedure Play;
  end;

or even better:

  TMediaItem = class(TObject)    
  public
   FileName: String;    
   FileExtension: String;    
   procedure Play; virtual;
  end;

  TSoundItem = class(TMediaItem)    
  public
   Loop: Boolean;    
   Volume: Integer;  
   procedure Play; override;
  end;

  TVideoItem = class(TMediaItem)    
  public
   //add video related properties
   procedure Play; override;
  end;

all the GUI now has to do is call the Play method of the object of the selected treenode. The object is far from complete though, that is up to you to.

I hope you catch my drift. Use OOP to it's full potential and you can make some nice things with simple code.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I guess nobody knows how to do this, all i wanted help with is how to store/assign different values and information to a new created treenode, then recall this stored values when i later click on the coresponding node.

i think i should try roo's way again, i got very close to it working and whos your daddy seems to have gone :(
 
As much as I'd like to take credit, I think you meant Glenn. I do hope Daddy has recovered and I too was looking forward to reading his input. You could pursue his initial suggestion and look at TTreeNode object property 'Data'.

@Daddy - Get well my friend!

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top