Board index » delphi » Need help in some problem

Need help in some problem

I have got the following problem :

1.     How to tell a file is a ASCII text file or binary file other than the
extension ?
2.    When I use MediaPlayer.Play method to play the media autometically
after loading
        the file, the icons in the MediaPlayer Bar do not update it status
(i.e. Play button
        still enable while Stop & pause buttons disabled) Shall I change the
status
        manually ?  ( the autoenable is set to true )

Can anyone help.

 

Re:Need help in some problem


Quote
Justmade wrote:

> I have got the following problem :

> 1.     How to tell a file is a ASCII text file or binary file other than the
> extension ?

> Can anyone help.

Hi,
Try this:

function Test_4_ASCII_File(var readfile : File) : Boolean;
var
 NumRead : Word;
 Buf: array[1..254] of Byte;
 i : Integer;
 b1, b2 : Byte;
begin
 BlockRead(readfile, Buf, SizeOf(Buf), NumRead);
 Result := False;
 i := 1;
 repeat
  Inc(i);
  B1 := Buf[i-1];
  B2 := Buf[i];
  if (Buf[i-1] = 13) and (Buf[i] = 10) then
  begin
   Result := True;
   i := NumRead;
  end;
 until (i >= NumRead);

end;{Test_4_ASCII_File}

This function looks into the first 254 bytes of the file to get the
CarriageReturn/LineFeed of a ASCII file. Returns True if this was found
(False if not).
But: Some dudes make ASCII files only with CarriageReturn (or LineFeed?)
[like the MAC!!]. With this function You can check for correct PC-ASCII
files :-)
The code was made quick an dirty, so dont blame me ;-)

Hope You got a hint
Pat

PS. Why the hack do we need 2 chars for a new line?

Re:Need help in some problem


On Fri, 23 Jan 1998 17:33:01 +0100, Pat Keel

Quote
<Patrick.K...@cch.cerberus.ch> wrote:
>PS. Why the hack do we need 2 chars for a new line?

I think it stems from the pre-PC days. In the days when mainframes
were the only computers around, double-strike (or bold) and
underlining could only be done by printing a line of text, then
returning the printer head to the beginning of the same line (using
CR), and printing the text that had to be in bold or underscored
again. After that a LF would be used to move the printer head to the
next line. Early PC printers posed similar restrictions, and nobody
has revised the basic printer instruction table (if one might call it
that) yet. A lot of the things PCs do are still done in very much the
same way as they have been for the past fif{*word*249} to twenty years.
This might be for reasons of backward compatibility (time to tell
those 8088 users to upgrade their hardware!).

Re:Need help in some problem


Quote
>PS. Why the hack do we need 2 chars for a new line?

This goes back to the good old times of the telex machine.
The carriage had to be returned to the beginning of the line, after
came the "line feed".  The first generation of mechanical typewriters
couldn't do both at the same time...

In the beginning these machines were used for computer input and
output (TTY).  You could operate the old C/PM operating system with a
typewriter.

The reason it is still used today is M* backward compatibility :)

Michael

Other Threads