Hello,

Firstly, I would like to say i'm kinda new to programming, so this maybe just a simple error. But the fact is, its been troubling me for days now, and I can't seem to find out how to fix it

Anyway,
I am unable to run my program, The area I have highlighted in red is the problem, and I get the message "Object or Class type Required)

unit Unit2;

interface

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

  const examinername = 'Examiner.Dat';
  centrename = 'Centre.Dat';
  AdminPay = '95';
  TaxRate = '0.78';
  Subject1 = '4.52';
  Subject2 = '3.75';
  Subject3 = '7.88';

  Type
  examinertype = record
  ExamName:string[50];
  ExamNum:string[6];
  ExamAdd:String[50];
  SubRefCode:string[5];
  Taxflag:boolean;
  end;

 
centretype = record
CentNum: string[5];
SubRefcode: string[5];
ExamNum: string[6];
NumOfCand: integer;

  end;

type
  TForm2 = class(TForm)
    Label1: TLabel;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    MaskEdit3: TMaskEdit;
    MaskEdit4: TMaskEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    CheckBox1: TCheckBox;
    Label6: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
{    procedure Button2Click(Sender: TObject);  }
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
 examinerFile : file of examinertype   ;


implementation

{$R *.dfm}


procedure TForm2.Button1Click(Sender: TObject);
begin
assignfile(examinerfile, examinername);

Reset(examinerfile);

seek(examinerfile, filesize(examinerfile));

examinertype.examname := maskedit1.text;

examinertype.examnum := maskEdit2.text;

examinertype.examadd := maskedit3.text;

examinertype.subrefcode := maskedit4.text;

If checkbox1.checked = true then

examinerrec.taxflag := true;

If checkbox1.checked = false then

examinerrec.taxflag := false;}

 

{write(examinerfile,examinertype);     

Closefile(examinerfile);

maskEdit1.text := '';

maskedit2.text := '';

maskedit3.text := '';

maskedit4.text := '';

 

showmessage('Record has been added!');

checkbox1.checked := false;
end;



end.

I would really appreciate your help on this., I can't find out what i've been doing to make this error, but I believe it maybe something to do with the variables, but, as I am new to this, I can't work out what.

Thanks

here you can find an example of how to use Write typed records to a record type binary file

http://www.delphibasics.co.uk/RTL.asp?Name=Write

1) you should append the file not reset it
2) when you encounter that error hit f1 and you see which is the problem: you try to assign values to the type(examinertype), instead to assign values to a variable of type examinertype.

best regards,

Thank you for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.