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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Untyped file declaration throws an error

Status
Not open for further replies.

Hopperito

Programmer
May 23, 2004
3
0
0
US
There may be an easy answer to this, but I've searched for an hour with no luck at all.

I'm using Delphi 8, and I'm trying to read a binary file. When I try to declare a variable as an untyped file, as in...

myFile : File;

I get an error... "Unsupported Language Feature: 'typed or untyped file'"

My uses are;
System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data, Dialogs, System.IO,
Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, ExtCtrls, FileCtrl, System.Resources;

I know that is a lot of unnecessary uses, but I'm a newbie to Delphi and I was trying to see if something was missing from the uses section.

Please help!

Thanks - Hop
 
Hi,

You need to use the 'FileStream' class, if you want to be able to read from binary files. See example:

uses
System.IO;


procedure YourProc;
var
AFileStream : FileStream;
AFileReader : BinaryReader;
begin
AFileStream := FileStream.Create('c:\yourfile.bin', FileMode.Open, FileAccess.Read);
AFileReader := BinaryReader.Create(AFileStream);

{ Process the file using the BinaryReader class methods }

AFileReader.Free;
AFileStream.Free;
end;

Hope this helps.
WB
 
Thanks for your reply!

Your solution did indeed work, but I have a question.

Does this mean I can't declare typed or untyped files? I tried the typed approach using examples I found via a google search, and that failed too. Did this work on older versions of Delphi? It's really weird because 'file' turns bold, like it's an identifier, but throws the error no matter what I put after it, like 'of byte', 'of text', 'of [a declared type name]', etc.
 
Yes, you can not declare typed or untyped files. This is considered 'unsafe' in the .NET framework and therefore the compile wont accept them.

Yes, They did work in versions of Delphi prior to 8 and the reason it goes bold when you delcare it, is because it is a reserved word.

WB
 

#IRONY MODE ON

05/25/04 - CNN Exclusive

REVOLUTIONARY MOVE IN COMPUTER PROGRAMMING

In a revolutionary and unexpected move, Microsfot decided to reshape the way computer programms are written.

"We need to protect all those unskilled programmers safe from its own stupidity" a Microsfoft spokerperson said.

"You know... we started banning pointers from VB years ago... pointers are unsafe... it is not enough anyway... those guys are very stubborn and continue doing wrong things and claiming it is our fault... so we decided to drop files too" the representative explained.

"We are not going to stop here. At Microsoft we believe languajes have too many features for the average programmer... they are kinda dumb, you know... we are going to remove unnecesary control structures like 'while' and 'repeat' and keep only 'if... then... else...' and 'goto'. A feature-rich languaje is unsafe." he added.

"We are going to remove any data-typing too... modern programming don't need no typing. Data-typing is unsafe; you can't rely on the programmer to decide what types his variables need to have" he said.

"Look at VBS: other than having some unnecesary and seldom used control structures like 'while' it is safe, it is easy and any medium-skilled programmer can deal with it... the real problem VBS still have is the lack of line-numbering; but we are looking into this. Forcing the programmer to name his own labels is unsafe, you know, they end making a mess with the names."

"Sure some guys are claiming we are turning the whole industry back 20 years... you know... programmers are like the FTC: they're never happy, no matter what you try."

#IRONY MODE OFF

buho (A).
 
lol Buho, nice peace.

I find the whole thing weird anyway since Delphi8 help doesn't mention it's forbidden. I mean open help and type 'file' as search item and you'll get the whole thing explained? I've installed delphi8 3 months ago and played with it twice, but I keep running back to delphi7. I wonder why...

--------------------------------------
What You See Is What You Get
 
Thank you Buho for making what I've been saying for years factual, albeit fiction. Conforming to the standards that is dotnet is probably a mamoth task to say the least, and I can forgive Borland for forgetting to remove the possibility of declaring untyped files from the help documentation.

And thank you to whosrdaddy for the indirect advice about doing what I should be doing... learning in D7.

Hop

p.s. Thanks wildbash for why 'file' goes bold. I knew it was a reserved word for that reason, which led me to believe it had some importance. I didn't think about what that importance was meant to imply, thus being utterly frustrated. =|
 

IMO, worse than that is D6 saying nothing about Synchronize not working anymore in DLLs. A lot of my code got broken when migrated from D5 to D6 and I needed to figure out why by myself.

Well... "don't be the first one embracing the new trends; don't be the last man discarding the old ones."

A survival rule if you are a programmer.

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top