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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Typed Record question 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
Could I merge these two records into one?

TMember = Record
Projectname : string[40];
Projectexport : string[1];
ProcessName : string[40];
Method : boolean;
TrialCounter : Integer;
end;

TMemberTrial = record
Trialname : String[40];
Redvalue : Integer;
GreenValue : Integer;
BlueValue : Integer;
Info : String[255];
end;

myFile : File of TMember; // A file of customer records
Member : TMember;
MyTrial : File of TMemberTrial;
MemberTrial : array [0..50] of TMemberTrial;

The trailcounter variable tells me on how many record the membtrial is going to be.

Thanks.
Pierrotsc
 
Delphi doesn't directly support variable record structures, so merging them would be out of the question. If these structures occur in the same file, you can blockread the main record and then blockread the MemberTrial structure based on the TrailCounter variable.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy
 
Yes, they occur in the same file. Should I google blockread to find out on how to do that?
Thanks.
 
Really all you need to do is open the file as an untyped file with a blocksize of 1 and then successively read the structure.

Code:
{ untested}
reset(myfile, 1);
blockread(myfile, Member, sizeof(Member), actualread);
if Member.TrialCounter > 0 then
  blockread(myfile, MemberTrial, sizeof(Member) * Member.TrialCounter, actualread);

Error code is probably advisable on the "actualread" variable to make sure you are reading what you are expecting.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top