SRL Archive - OSR Help

Getting back into programming in SRL/SIMBA


Eduard

2012-12-12 15:14:40

Hi guys,

just refreshing up my PASCAL/SIMBA a little bit.
Just wondering, what's wrong with this code?

program IOtest;
var
iCreateFile,iAppendFile:integer;
bString:Boolean;

const
sFilePath = 'C:\CurrentStatusBot.txt';
sStringToWrite = 'Bot is up!';

begin
iCreateFile = CreateFile(sFilePath); //create handle for closing file();
if (iCreateFile <> -1) then // if no error then proceed.
begin
CloseFile(iCreateFile); // close created file.
iAppendFile = Appendfile(sFilePath); // create handle for appending file.
if (iAppendFile <> -1) then // if no error then proceed.
begin
bString = WriteFileString(iAppendFile,sStringToWrite); // error checking variable.
if(bString <> false) then // if writefilestring was succesfull then
begin
writeln('Everything went succesfully!'); // writeln();
CloseFile(iAppendFile);
end
end
end
end.

[Error] (12:36): Internal error (20) at line 11
Compiling failed.

Eduard

2012-12-12 15:19:12

Nevermind, should have checked the syntax.

Rezozo

2012-12-12 15:21:11

Problem solved? I see a couple I think ;)
Semi colon after End's. first. Try that lol

J J

2012-12-12 15:27:21

From: Eduard
Nevermind, should have checked the syntax.

Yeah there were some Syntax errors, probably because you are coming from another language :P

Proper syntax:
program IOtest;
{$i SRL/srl.simba}

var
iCreateFile,iAppendFile:integer;
bString:Boolean;

const
sFilePath = 'C:\CurrentStatusBot.txt';
sStringToWrite = 'Bot is up!';

procedure TestIO;
begin
iCreateFile := CreateFile(sFilePath); //create handle for closing file();
if (iCreateFile <> -1) then // if no error then proceed.
begin
CloseFile(iCreateFile); // close created file.
iAppendFile := Appendfile(sFilePath); // create handle for appending file.
if (iAppendFile <> -1) then // if no error then proceed.
begin
bString := WriteFileString(iAppendFile,sStringToWrite); // error checking variable.
if(bString <> false) then // if writefilestring was succesfull then
begin
writeln('Everything went succesfully!'); // writeln();
CloseFile(iAppendFile);
end;
end;
end;
end;

begin
SetupSRL;
TestIO;
end.

But don't you want to close the file regardless if you succesfully wrote to it? :P