The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > Others > Delphi


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 08-31-2007, 08:26 AM
Destriarch Destriarch is offline
Novice
Join Date: Aug 2007
Posts: 6
iTrader: (0)
Destriarch is on a distinguished road
Handling Files and Streams in Delphi

I've been programming little amateur applications in Delphi for a long time, but one thing has always confused me. I've searched in vain for a tutorial on this exact subject, but so far a solution has eluded me.

Basically, what I want to do is to write numerous different types of data into one big file. For example, I might want to store three JPGs and four integer values, then restore them.

I've been looking at using TFileStream to do this, and I've managed to get it to write and read a single JPEG into a file which is great. However I can't get it to write two JPEG images into the same file, or rather I can get them to write in, but when I try to extract them again I only get the first JPEG out before the program shows an error message (JPEG error #42). The code is below. Can anyone tell me what I'm doing wrong? It's driving me crazy!

'Figure' is a variable of type TFileStream. 'Image' and 'Image1' are standard image components used for test purposes.

File Writing Procedure:
figure := tfilestream.Create('test.fig',fmcreate);
image.Picture.Graphic.SaveToStream(figure);
image1.Picture.Graphic.SaveToStream(figure);
figure.Free;

File Reading Procedure:
figure := tfilestream.Create('test.fig',fmopenread);
image.Picture.Graphic.LoadFromStream(figure);
image1.Picture.Graphic.LoadFromStream(figure);
figure.Free;

Thanks in advance!

Ash

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #2 (permalink)  
Old 08-31-2007, 10:20 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
Basically, what I want to do is to write numerous different types of data into one big file. For example, I might want to store three JPGs and four integer values, then restore them.
Why you'd want to store image in the integers? Personally, I always store images in bytes[] array. Moreover, when all types of data is broken down, I believe it will went down to bytes anyway. Sorry if this is to abstract, but there must be a way for it to retrieve if when we keep track the index of the bytes array...?

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 08-31-2007, 10:31 AM
Destriarch Destriarch is offline
Novice
Join Date: Aug 2007
Posts: 6
iTrader: (0)
Destriarch is on a distinguished road
You misunderstand me. I don't want to store a JPEG IN integers, I want to save a JPEG in the same file as integer values, along with other JPEGs for that matter.

I'm convinced that the problem is something to do with recalling the image from the file, rather than how I'm storing it though. Maybe there's another way to restore an image from stream, rather than using the loadfromstream command...

Ash

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #4 (permalink)  
Old 08-31-2007, 11:27 AM
Destriarch Destriarch is offline
Novice
Join Date: Aug 2007
Posts: 6
iTrader: (0)
Destriarch is on a distinguished road
Right, I think I've confirmed that the problem is not in how I'm writing the files; that I think I've sorted out to my own satisfaction. The problem is that the Graphic compenent isn't loading the image from the stream properly for some reason. I've tested this out by having the images saved back to file after extraction, and they come out just fine. So why can't I get it to load from a copied stream..? This is really, totally illogical.

Ash

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 08-31-2007, 11:37 AM
Destriarch Destriarch is offline
Novice
Join Date: Aug 2007
Posts: 6
iTrader: (0)
Destriarch is on a distinguished road
It's always the simple things, isn't it?

I still don't know why the original code wasn't working, but I have now found a way to make it work properly. Thanks for the help anyway.

Ash

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #6 (permalink)  
Old 08-31-2007, 11:54 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
However I can't get it to write two JPEG images into the same file
Sorry, I don't really understand what you meant by writing two JPEG images into the same file? Is this even possible? You want to combine them? What kind of file you're talking about...? ASCII file? Or you're just wanted to write the name of the JPEG image... or...

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #7 (permalink)  
Old 08-31-2007, 12:03 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
Its ok now mate, he has it fixed, glad to see you fixed it destriarch, would you care to post the answer? Just so in future when people look for the answer they can find it easily
Reply With Quote
  #8 (permalink)  
Old 08-31-2007, 12:05 PM
Destriarch Destriarch is offline
Novice
Join Date: Aug 2007
Posts: 6
iTrader: (0)
Destriarch is on a distinguished road
Quote:
Originally Posted by HelloWorld View Post
Sorry, I don't really understand what you meant by writing two JPEG images into the same file? Is this even possible? You want to combine them? What kind of file you're talking about...? ASCII file? Or you're just wanted to write the name of the JPEG image... or...
Yep, it's possible, I just managed it. Basically, you open up a filestream, then write in the size of the image in bytes, followed by the image itself. When you read it out again, you simply read the size first (which, as an Int64 variable, has a set predictable length) and use that to read the image which follows it without overrunning. The problem I was having was that I didn't realise the tstream.copyfrom procedure updates the position of the stream that is copied to as well as the stream which is copied from.

Ash

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #9 (permalink)  
Old 01-23-2008, 07:47 PM
DanDare DanDare is offline
Novice
Join Date: Jan 2008
Posts: 6
iTrader: (0)
DanDare is on a distinguished road
Ok Im the newest registered used.

Hello Destriarch,

Im now at same situation as you was in the past.... stucked into JPEG error while trying to retrieve the solid archive of jpeg images in DELPHI using LoadFromStream .

I tried lot of searchs on internet and even tried to understand how do you fixed this But just cant got the thing working and im not any advanced user anyway.

Can you post how the code must be done to have it working?

Thanks in advance


(dont care too much about my english,.... isnt my native language)

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by DanDare : 01-23-2008 at 07:53 PM.
Reply With Quote
The Following User Says Thank You to DanDare For This Useful Post:
HelloWorld (01-23-2008)
  #10 (permalink)  
Old 01-23-2008, 08:51 PM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
sounds like you need a database buddy... store the data as BLOB's (Binary Large Objects) in the database and pull them out with Delphi
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 11:51 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50