Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error 217 at 004536FF...any ideas??!

Status
Not open for further replies.

kaywarner

Technical User
Jan 8, 2010
24
GB
Hi All,

Thanks for taking the time to read the post, here's whats happend;

I've written a tutorial example of code which loads a Text file into a Dynamic Array.

the problem is that at runtime I get the following;

"Runtime Error 217 at 004536FF".

When I tried to fix this myself the solution lead me to a help file that said this was a fatal I/O error caused by an 'EControlC' event. I then found out that this means that I pushed 'Ctrl + C'.

But here is the catch....i didn't!!!! :)

It would be a great help if anyone could shed any light on this...?

Thanks to all,

Kay
 
can you show the code?

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Hi Daddy,

yeah sure, i've got;


////////////////////////////////////////////
/ Txt File to Dyn Array Prog /
////////////////////////////////////////////


programme Project1

{$APPTYPE CONSOLE}

Uses

SysUtils;

Var

MyFile : Text
lines : array of string;
cnt: Integer;
fileName: string;

Function GetLineCount (var ATextFile: Text); Integer

begin

result:= 0

while not Eof (ATextFile) do

begin
ReadLn (ATextFile);
Inc (Results);
end

Reset (ATextFile)

end;



fileName := 'c\data.txt'

AssignFile (myFile, fileName);

{$I-}
reset (myFile)
{$I+}




If IOResult = 0 then

begin

SetLength (lines.GetLineCount(myFile));

for cnt := Low (lines) to High (lines) do

ReadLn(myFile, lines[cnt]0

CloseFile(myFile);

for cnt:= low (lines) to high (lines) do
WriteLn (UpperCase(lines[cnt]));

end

else

WriteLn ('Can't Open : ', fileName);

ReadLn;

end

thanks...Kay
 
Dunno about the specific error, but there is not a great deal of error trapping in that!


Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 

There is a lot that is wrong with what you posted (doesn't compile), I would suggest that you fix those things. This includes some of your methodology, along with error checking, as was mentioned.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy
 
With a minimum of tweaking I was able to get it to compile and run as desired:
Code:
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

Var
  MyFile: Text;
  lines: array of string;
  cnt: Integer;
  fileName: string;

Function GetLineCount(var ATextFile: Text): Integer;
begin
  result:= 0;
  while not Eof(ATextFile) do begin
    ReadLn(ATextFile);
    Inc(Result);
  end;
  Reset(ATextFile);
end;

begin
  fileName:= 'c:\data.txt';  //This was perhaps your biggest problem
  AssignFile(myFile, fileName);
  {$I-}
  reset(myFile);
  {$I+}
  If IOResult = 0 then begin
    SetLength(lines, GetLineCount(myFile));
    for cnt:= Low(lines) to High(lines) do
      ReadLn(myFile, lines[cnt]);
    CloseFile(myFile);
    for cnt:= low(lines) to high(lines) do
      WriteLn(UpperCase(lines[cnt]));
  end else
    WriteLn('Can''t Open : ', fileName);
  writeln('---end---');
  write('Press enter to close...');
  ReadLn;
end.

Roo
Delphi Rules!
 
Biggest problem, yes illustrates the need for error checking, its never a good idea to hard code file paths into a program.

Even if its just a test program I would use the
'iffileexits(filename)' function to trap my possible typos, inadvertent moving of files etc.



Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
IMO, considering the scope of the project, the IOResult return code is adequate...
Code:
  If IOResult = 0 then 
    //success - continue
  else
    WriteLn('Can''t Open : ', fileName);
... as it was back in the days of Turbo Pascal.

Roo
Delphi Rules!
 
Thanks guys, i'd be stuck dead without you lot!!

I've been trying to build up the code segment by segment to try and find the error but this has helped loads.

If I want to put the array into a TMemo (assuming that I add this into a VCL application), the compile error says "incopatible types 'String' and 'TStrings'" which I can't quite iron out.

I was under the impression that 'array of string' was a string and 'Memo1.Text' property accepted strings? have i got this correct?

thanks to all,

Kay
 
what is the code you're using to try and put the array in the TMemo?


Leslie
 
I was under the impression that 'array of string' was a string and 'Memo1.Text' property accepted strings? have I got this correct?
Not exactly...

1st: Understand that a string (type String) is an array of characters.

2nd: Memo1.Lines (type TStrings) is an array of string.

3rd: Memo1.Text is an AnsiString composed of all lines combines, including the <CR><LF> chars between the lines. I suggest totally avoiding use of the Text propery unless you totally understand its usage. [See "Long String" in Delphi Help for more info.]

Typically, (at run-time) you add lines of text to the Lines array with the Add function. Like this:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add('another line of text')
end;

Optionally, you can pre-load Memo1.Lines a design-time from the Object Inspector.

HTH

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top