Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to save multiple records and an integer into one file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Oct-02
Category
Files Operation
Language
Delphi All Versions
Views
147
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I am writing an adventure game and need to store information in a save game. The 
game requires data from 3 different records and one variable

record1 = hotspot scene information(50 recs),
record2 = conversation information (60 recs),
record3 = hypertext information(50 recs)
variable = integer - # of scene currently on.

My problem is that I need to seek for a particular record of particular type in the 
file (I do not want to have to keep huge arrays of records in memory). I know how 
to do this with a file containing records of only one record type but have no clue 
how to combine all three records and one integer into a single random access file.

Answer:

I generally use a file with a header, then just keep the header in memory and use 
it to seek to the records I need.

1   type
2     TSaveHeader = record
3       scene: Integer;
4       hotspots: LongInt;
5       talk: LongInt;
6       hype: LongInt;
7     end;
8   
9   var
10    SaveHeader: TSaveHeader;
11  
12  procedure OpenSaveFile(fname: string);
13  var
14    f: file;
15    i: Integer;
16  begin
17    AssignFile(f, fname);
18    Reset(f, 1);
19    BlockRead(f, SaveHeader, Sizeof(TSaveHeader));
20    { get one set of records }
21    Seek(f, SaveHeader.hotspots);
22    for i := 1 to 50 do
23      BlockRead(f, somevar, sizeof_hotspotrec);
24    { and so on }
25    CloseFile(f);
26  end;
27  
28  { assuming the file is open }
29  
30  procedure GetHotspotRec(index: LongInt; var hotspotrec: THotspot);
31  var
32    offset: LongInt;
33  begin
34    offset := SaveHeader.hotspots + index * Sizeof(THotSpot);
35    Seek(f, offset);
36    BlockRead(f, hotspotrec, Sizeof(THotspot));
37  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC