BP7 questions about random filenames and text input 
Author Message
 BP7 questions about random filenames and text input


Quote:
> Hi,
> I would like for my program to be able to accept long strings of input
> (i.e. notepad or something), currently I am just using ReadLn which is
> limited to about 255 char or something.
> Also,
> I would like for this same program to generate random file names but
> with a specific format (i.e. S8990800.899 etc...).
> Where should I be looking?
> thanks
> -shawn

Look in the help for information about reading a file into a text buffer.
Sorry I can't be more specific as I don't have access to the software at
present. I know there is a reasonable section in the help and the
documentation about this.

As for random file names you will need to use random. Check help on this
for further information.

Paul



Sun, 12 Dec 1999 03:00:00 GMT  
 BP7 questions about random filenames and text input

For TurboPascal, you can use READ (not READLN) to read a very long
line in a text file in chunks of 255 characters.  When there are no
more characters on the line, the target string variable will have a
resulting length of 0.  When that happens do a READLN to advance to
the next line in the file.

On the random file names, if you are expecting that someplace in the
documentation or online there is a discussion on the proper way of
creating a random file name, there is none.  The following untested
function should extract ResLength characters at random from the Source
string:

 function  RandomChars( ResLength:byte; const Source:string):string;
 var i:integer;
 var result:string; {not in Delphi}
 begin
   result:='';
   for i:=1 to ResLength do
       result:=result+Source[random(length(source))+1];
   RandomChars:=result; {not in Delphi}
 end;

You can form random filename from making several calls to RandomChars
with different lengths and and source strings.

Quote:

>I would like for my program to be able to accept long strings of input
>(i.e. notepad or something), currently I am just using ReadLn which is
>limited to about 255 char or something.
>Also,
>I would like for this same program to generate random file names but
>with a specific format (i.e. S8990800.899 etc...).
>Where should I be looking?



Sun, 12 Dec 1999 03:00:00 GMT  
 BP7 questions about random filenames and text input

Quote:

> Hi,
> I would like for my program to be able to accept long strings of input
> (i.e. notepad or something), currently I am just using ReadLn which is
> limited to about 255 char or something.
> Also,
> I would like for this same program to generate random file names but
> with a specific format (i.e. S8990800.899 etc...).
> Where should I be looking?
> thanks
> -shawn

Here's a code fragment that will give you the DOS random file name (same
as used by DOS 'pipes' for temporary files). It's written to create a
text file but you can change the file pointer to whatever type you need.

{-----------------------------------------------------------------------}
{                                                                      

Quote:
}

{    Open a new, temporary, text file for write-only access.  The file
Quote:
}

{    name is returned to the caller.                                  
Quote:
}

{                                                                      
Quote:
}

{-----------------------------------------------------------------------}
procedure OpenScratch (var FPtr : text;
                       var FNam : string;
                    var Success : boolean);

var
  Regs : registers;
  Handle : integer;
  Len : byte;

begin
  GetDir (0, FNam);
  FNam := FNam + Chr(0);

  with Regs do
  begin
    DS := Seg(FNam[1]);
    DX := Ofs(FNam[1]);
    AH := $5A;
    CX := $0000;
    MsDos (Regs);

    Success := Flags and FCarry = 0;
    if Success then
    begin
      Handle := AX;
      Len := length(FNam);
      Len := Len + 12;
      FNam[0] := chr(Len);

      AX := $3E00;
      BX := Handle;
      MsDos (Regs);

{$I-}
      Assign(FPtr, FNam);
      Append(FPtr);
      Success := IOResult = 0;
{$I+}
    end;
  end;
end;

--
* Bill Decker                       | Customary disclaimer ... etc.  *
* please ignore nospam address ---->| reply to WDECKER(at)ACM(DOT)ORG*
*                                   | Computer Sciences Corporation  *
* http://www.geocities.com/SoHo/Studios/1450                         *
*     < It isn't procrastination if you put it off right away. >     *
*--------------------------------------------------------------------*



Mon, 13 Dec 1999 03:00:00 GMT  
 BP7 questions about random filenames and text input

Quote:

>Hi,
>I would like for my program to be able to accept long strings of input
>(i.e. notepad or something), currently I am just using ReadLn which is
>limited to about 255 char or something.

Use read() and eoln(). You still have to device a way to store the long
strings. Alternatively you could use untyped files.

Quote:
>Also,
>I would like for this same program to generate random file names but
>with a specific format (i.e. S8990800.899 etc...).'

Random but specific??? How about writing the code yourself? There is a
DOS function to create a temporary file but that is not of specific
format.

Osmo



Tue, 14 Dec 1999 03:00:00 GMT  
 BP7 questions about random filenames and text input



Quote:

>>Hi,
>>I would like for my program to be able to accept long strings of input
>>(i.e. notepad or something), currently I am just using ReadLn which is
>>limited to about 255 char or something.

<snipped>

The following is from Borland's Technical Information TI2645 -
How to readln longer than 255 chars.

Readln() will accept an array [0..something] of char as a buffer to
put the read character in and it will make a proper zero-terminated
char out of them. The only limitation is this: the compile needs to be
able to figure out the size of the buffer at compile time which makes
the use of a variable declared as Pchar and allocated at run-time
impossible.

Workaround:

Type
    { use the longest line you may encounter here }
    TLine = array [0..4096] of char;
    PLine = ^TLine;
Var
    PBuf : PLine;

...

   New (PBuf);

...
   ReadLn(F,PBuf);

Note: you can use a variable declared as of type TLine or an
equivalent array of char directly, of course, but I tend to allocate
anything larger than 4 bytes on the heap...

end of technical information

Although this is label Product Delphi, take heart, it apparently works
under Turbo Pascal 7.0 (at least it has for me). Clearly the nice part
about declaring it on the heap is that [0..32767] become very
practical and very unlikely to be "too small". Breaking up this
"pChar" is relatively simple compared to the previous problem.



Wed, 15 Dec 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. BP7 questions about random filenames and text input

2. BP7 questions about random filenames and text input

3. BP7 questions about random filenames and text input

4. Random filenames in BTP7.0

5. Random filenames in BTP7.0

6. BP7 / Long Filenames LFN

7. long filenames under BP7.0 ?

8. Release LFN v1.10 - Long filename unit for Win9x and TP6 up to BP7

9. Release LFN v1.10 - Long filename unit for Win9x and TP6 up to BP7

10. Release LFN v1.09 - Long filename unit for Win9x and TP6 up to BP7

11. Release LFN v1.09 - Long filename unit for Win9x and TP6 up to BP7

12. about random() in BP7

 

 
Powered by phpBB® Forum Software