Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6375935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:40:48+00:00 2026-05-25T01:40:48+00:00

When I compile the following code, I get errors. I don’t understand some of

  • 0

When I compile the following code, I get errors. I don’t understand some of them.

Code

program Lasagna;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils
  { you can add units after this };

{$R *.res}
type
  TVehicle = record
    kindOfVehicle : String[30];
    numberOfWheels : Integer;
    horsePower : Real;
  end;

var
  F: file of TVehicle;
  Vehicle : Array [1..3] of TVehicle;
  index : Integer;

begin
     writeln('A RECORD OF DIFFERENT KIND OF VEHICLES.');
     writeln('---------------------------------------');
     writeln;

     AssignFile(F,'C:/Users/W/Desktop/CarRecord.dat');
     writeln('Searching for file.');
     if FileExists('C:/Users/W/Desktop/CarRecord.dat') then
        begin
          writeln('File found. Opening file.');
          Rewrite(F);
          writeln('File ready.');
          writeln;
          writeln;

          for index:=0 to 3 do
          begin
            writeln('Enter the following details for vehicle no. ',index);
            write('Kind of Vehicle: ');
            readln(Vehicle[index].kindOfVehicle);
            write(F,Vehicle[index].kindOfVehicle);//line 45: this is a string so why do I get an error?**

            {Do NOT use writeln() when writing to random access files.}

            write('Number of Wheels: ');
            readln(Vehicle[index].numberOfWheels);
            write(F,IntToStr(Vehicle[index].numberOfWheels));//line 51: The int is converted to string, so i shouldn't get an error?

            write('Horse Power of Vehicle: ');
            readln(Vehicle[index].horsePower);
            write(F, RealToStr(Vehicle[index].horsePower));//line 55:  
            end;

          writeln('Done. Closing File.');
          CloseFile(F);
        end
     else
         Rewrite(F);
         CloseFile(F);
         writeln('File Not Found.');

     Writeln('Press ANY key to close the program.');
     Readln;
end.

Errors

Compiling Lasagna.lpr

Lasagna.lpr(45,49) Error: Incompatible types: got “ShortString”
expected “TVehicle”

Lasagna.lpr(51,60) Error: Incompatible types: got “AnsiString”
expected “TVehicle”

Lasagna.lpr(55,59) Error: Incompatible types: got “AnsiString”
expected “TVehicle”

Lasagna.lpr(70) Fatal: There were 3 errors compiling module, stopping

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:40:48+00:00Added an answer on May 25, 2026 at 1:40 am

    In line 21, you are declaring F as “file of TVehicle”. So, you should write TVehicle data to it, not strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code, I get a compile time error: ByRef Argument type mismatch.
In the following code, I get a compile time error because i is treated
For the attached code, I get the following compile time error : exception during
When I compile with the following code there are no errors: @class RootViewController; //#import
Can anybody tell me why the following code doesn't work? I don't get any
When I compile the following code, I only see the error during Run-time which
When I compile the following code with g++, the object of class A seems
When trying to compile the following code, I am getting a warning that line
I am trying to compile the following code: private String dataToString(){ Map data =
I am trying to compile the following code and i am getting the error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.