Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Another problem with my random or serial files

Hi,
Im trying to create either a random or a serial access file (either will do) but after writing the code and it being compiled no problem, the program will create the file but will not enter the information into the file.

My serial file code is written below:
--
unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
bttn_create: TButton;
bttn_exit: TButton;
procedure bttn_createClick(Sender: TObject);
procedure bttn_exitClick(Sender: TObject);
end;

wrestler_type = record
wrestler_number :integer;
stage_name :string[30];
card_status :integer;
belt_status :string[1];
end;



var
Form1: TForm1;
wrestler_file :file of wrestler_type;
wrestler_rec :wrestler_type;
count :integer;

implementation
{$R *.dfm}

procedure create_file;
begin
assign(wrestler_file, 'wrestlers.dat');
rewrite(wrestler_file);
count := 1;
repeat
wrestler_rec.wrestler_number := count;
wrestler_rec.stage_name := 'Empty';
wrestler_rec.card_status := 1;
wrestler_rec.belt_status := 'N';
count := count + 1;
until count = 99;
reset(wrestler_file);
close(wrestler_file);
end;


procedure TForm1.bttn_createClick(Sender: TObject);
begin
create_file;
end;

procedure TForm1.bttn_exitClick(Sender: TObject);
begin
close;
end;

end.
--
The file "wrestlers.dat" is created but with none of the information inputted.

This problem is really starting to annoy me now, lol, so any help you can give me would be appreciated.

Thanks,
Deanobajio

p.s I'm upgrading from TP7 which is probably the reason I can't see the problem :o)

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi,
    : Im trying to create either a random or a serial access file (either will do) but after writing the code and it being compiled no problem, the program will create the file but will not enter the information into the file.
    :
    : My serial file code is written below:
    : --
    : unit main;
    :
    : interface
    :
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, StdCtrls;
    :
    : type
    : TForm1 = class(TForm)
    : bttn_create: TButton;
    : bttn_exit: TButton;
    : procedure bttn_createClick(Sender: TObject);
    : procedure bttn_exitClick(Sender: TObject);
    : end;
    :
    : wrestler_type = record
    : wrestler_number :integer;
    : stage_name :string[30];
    : card_status :integer;
    : belt_status :string[1];
    : end;
    :
    :
    :
    : var
    : Form1: TForm1;
    : wrestler_file :file of wrestler_type;
    : wrestler_rec :wrestler_type;
    : count :integer;
    :
    : implementation
    : {$R *.dfm}
    :
    : procedure create_file;
    : begin
    : assign(wrestler_file, 'wrestlers.dat');
    : rewrite(wrestler_file);
    : count := 1;
    : repeat
    : wrestler_rec.wrestler_number := count;
    : wrestler_rec.stage_name := 'Empty';
    : wrestler_rec.card_status := 1;
    : wrestler_rec.belt_status := 'N';
    : count := count + 1;
    : until count = 99;
    : reset(wrestler_file);
    : close(wrestler_file);
    : end;
    :
    :
    : procedure TForm1.bttn_createClick(Sender: TObject);
    : begin
    : create_file;
    : end;
    :
    : procedure TForm1.bttn_exitClick(Sender: TObject);
    : begin
    : close;
    : end;
    :
    : end.
    : --
    : The file "wrestlers.dat" is created but with none of the information inputted.
    :
    : This problem is really starting to annoy me now, lol, so any help you can give me would be appreciated.
    :
    : Thanks,
    : Deanobajio
    :
    : p.s I'm upgrading from TP7 which is probably the reason I can't see the problem :o)
    :
    The problem is that you don't write the data anywhere into the file. You need to add the following line somewhere in your procedure:
    [code]
    write(wrestler_file, wrestler_rec);
    [/code]
  • deanobajiodeanobajio Posts: 5Member
    Thanks for that, having one of those 'duh!' moments now :o)

    Thanks,
    Deanobajio

Sign In or Register to comment.