Forum > Beginners
Problems readig archive files
jcaser1948:
I try to rewrite my old Turbopascal MotorCalculation Program in Lazarus.
I have still Problems readig existig files
Here the code
procedure TForm1.MenuItem1Click(Sender: TObject);
var
filename: string;
begin
if OpenDialog1.Execute then
begin
filename := OpenDialog1.Filename;
ShowMessage(filename);
ReadFile( filename); ;
end;
end;
And here is the Procedure Readfile
{---------------------------------------------------------------------------}
PROCEDURE TForm1.ReadFile( var filevar: string);
VAR
LocalMotorname:String;
ok:Boolean;
Answer :Char;
BEGIN
REPEAT
LocalMotorname:='????????.MOT';
{DirList; }
WRITELN;
WRITELN('NAME OF FILE TO BE LOADED ?(without extension) ');
READLN(LocalMotorname);
LocalMotorname:= StringUpper(LocalMotorname);
WritelN(LocalMotorname);
LocalMotorname := LocalMotorname + '.MOT';
ok:=false;
StringUpper(LocalMotorname);
writeln;
WRITELN((LocalMotorname),' FILE WILL BE LOADED');
IF NOT FileExists(LocalMotorname)
THEN
BEGIN
WRITELN('CAN NOT find file :',LocalMotorname);
WRITELN;
WRITELN;
ok:=False;
END;
IF FileExists(LocalMotorname) THEN
BEGIN
AssignFile(filevar,LocalMotorname);
And here I get this error
datenfile1.pas(1975,26) Error: Call by var for arg no. 1 has to match
exactly: Got "AnsiString" expected "TypedFile"
What can I do to correct the error ?
TRY
RESET(filevar); // Open the file for reading
and here the other error
datenfile1.pas(1978,31) Error: Call by var for arg no. 1 has to
match exactly: Got "AnsiString" expected "Text"
// Keep reading lines until the end of the file is reached
while not eof(filevar) do
BEGIN
READLN(filevar,dia);
READLN(filevar,mes);
READLN(filevar,anho);
READLN(filevar,motortyp);
READLN(filevar,Bearbeiter);
READLN(filevar,Statorblechnr);
READLN(filevar,Rotorblechnr);
READLN(filevar,Angebotsnummer);
READLN(filevar,kenrot);
READLN(filevar,schltg);
READLN(filevar,polzahl);
READLN(filevar,motfil);
READLN(filevar,pabkw);
READLN(filevar,uv);
READLN(filevar,freq);
READLN(filevar,cosphi);
READLN(filevar,etam);
READLN(filevar,delta);
READLN(filevar,N1);
READLN(filevar,n2);
{some 20 Variable more in the same line}
READLN(filevar,Brst25);
READLN(filevar,Rst25);
{ReadData End}
ok:=true;
END;
except on E: EInOutError do
writeln('File handling error occurred. Details: ', E.Message);
end;
CloseFile(filevar);
writeln('File ', LocalMotorname, ' was read. Press enter to continue.');
readln;
Motorname:=LocalMotorname;
WriteDataToScreen;
END;
WRITELN(LocalMotorname,' loaded. Do you want to load another Motor File
instead?(Y/N) ');
readln;
If Answer= 'Y' Then ok:= False Else ok:= True;
UNTIL ok=True;
END;
datenfile1.pas(1975,26) Error: Call by var for arg no. 1 has to match
exactly: Got "AnsiString" expected "TypedFile"
Where arises the Type mismatch?
Has someone a better example how to read old archives in Lazarus with new components, but using the existing files?(They are Motor Calculation files and it would be very tiresome to write them again)
Help would be appreciate
marcov:
That is not a program that would compile in Turbo Pascal either.
Assign and reset do take a first argument of type TEXT or TEXTFILE, not filevar: STRING
lucamar:
The type-mismatch arises because filevar *is* a string (as declared in the procedure header) but you're trying to use it as if it were of type file --- p.e. when your code says: AssignFile(filevar,LocalMotorname);
What I would do is use LocalMotorname as the parameter of the procedure, declare filevar: Texfile and delete all the start code until: WRITELN((LocalMotorname),' FILE WILL BE LOADED'); ... After all you have *already* selected a file through the OpenFileDialog!!!
howardpc:
You are trying to mix console-oriented readln code with GUI code in the most inappropriate way.
Once you have the name of the file from your OpenDialog1 component, create a TStringList (uses Classes;) and use the LoadFromFile(OpenDialog1.Filename) method of the stringlist to read the file content into the list.
You want some variation on this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var sl: TStringList;begin sl:=TStringList.Create; try sl.LoadFromFile(OpenDialog1.Filename); Assert(sl.Count=<whatever>,'Unexpected number of lines in '+OpenDialog1.Filename); dia:=sl[0]; mes:=sl[1]; anho:=sl[2];... Brst25:=sl[sl.Count-2]; Rst25:=sl[sl.Count-1];... Do something with all the strings you have read... finally sl.Free; end;end;
jcaser1948:
Dear Howard Pc
I Am trying yor solution
Here the code so far {---------------------------------------------------------------------------}
PROCEDURE TForm1.ReadFile;
VAR
filename:string;
LocalMotorname:Textfile;
sl: TStringList;
BEGIN
OpenDialog1.Execute ;
filename:= OpenDialog1.filename;
ShowMessage(Filename);
sl:=TStringList.Create;
try
sl.LoadFromFile(OpenDialog1.Filename);
Assert(sl.Count=81,'Unexpected number of lines in '+OpenDialog1.Filename);
dia:=sl[0];
mes:=sl[1];
anho:=sl[2];
motortyp:= sl[3];
Bearbeiter:= sl[4];
Statorblechnr:= sl[5];
Rotorblechnr:=sl[6];
Angebotsnummer:= sl[7];
kenrot :=StrToFloat(sl[8]);
schltg := sl[9];
polzahl .....
Kenrot ,schltg....are real numbers , since this is a motorcalculationsprogramm.
When I try to convert Kenrot from a String to a real number Iget
datenfile1.pas(1949,14) Error: Incompatible types: got "Extended" expected "LongInt"
Any suggestions?
Navigation
[0] Message Index
[#] Next page