Scrolling text file 
Author Message
 Scrolling text file

I am looking for a way to scroll through a text file (in DOS) using TP
6.  I am able to view the file but I want to be able to scroll up and
down through the file if it is bigger than one screen.  Please any
advice is appreciated.


Wed, 18 Jun 1902 08:00:00 GMT  
 Scrolling text file
Quote:

> I am looking for a way to scroll through a text file (in DOS) using TP
> 6.  I am able to view the file but I want to be able to scroll up and
> down through the file if it is bigger than one screen.  Please any
> advice is appreciated.

How about reading all lines into an array of strings?

Just some short snippets:

PString = ^string;
myfile  : array[ 0.. 100 ] of PString;
t       : text;
s       : string;
i       : integer;

i := 0;
repeat
 readln( t, s );
 getmem( myfile[i], length(s)+1 );
 myfile^[i] := s;
 { If won't work, use: Move( s, myfile[i]^, length(s)+1 ); }
 inc( i );
until eof( t );

Then scrolling should be no problem anymore! Just display not beginning
from the first line but e.g. from myfile^[2]!
(I hope this optimization thing with the getmen works... I'm not
completely sure... else just do
myfile : array[ 0..100 ] of string!

regards
--

------------------------------------------------------------------------
Member of Grey Dreams Design: visit http://GreyDreams.home.pages.de !!!!
He who can destroy a thing has the real control over it. (Frank Herbert)
------------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 Scrolling text file


Quote:

>I am looking for a way to scroll through a text file (in DOS) using TP
>6.  I am able to view the file but I want to be able to scroll up and
>down through the file if it is bigger than one screen.  Please any
>advice is appreciated.

Web <URL: http://www.merlyn.demon.co.uk/shower.pas>  - slight changes
will be needed for TP6 (it uses BREAK, for example, to exit loops).

--

  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.



Wed, 18 Jun 1902 08:00:00 GMT  
 Scrolling text file

Quote:
> I am looking for a way to scroll through a text file (in DOS) using TP
> 6.  I am able to view the file but I want to be able to scroll up and
> down through the file if it is bigger than one screen.  Please any
> advice is appreciated.

   Try this code (more than you want or need, but the concept should
help):
program Text_File_Viewer;                        { MRCopeland 941231 }
{$M 8192,0,655000}
Uses CRT,DOS,Printer,FastTTT5,WinTTT5,RPUa;

const Version = '1.0';
      TLim    = 10000;                               { Records Limit }
type  S80     = string[80];
      LLPTR   = ^S80;
var   I,J,K   : integer;
      PAX,B,E : integer;                       { Pointer Array indeX }
      OffSet  : integer;
      Done    : boolean;
      T       : S80;
      PA      : array[1..TLim] of LLPTR; { Pointer Array for records }

procedure Header;
begin
  ClrScr;
  WriteCenter (2,LightGray,Black,'**** Scrolling Viewer - Ver '+Version+'
****');
end;  { Header }

procedure Initialize;                 { initialize system & variables }
begin
  Header;
  if ParamCount > 0 then F3 := ParamStr(1)
  else
    begin
      WProm (LoNorm,'Enter filename: '); readln (F3)
    end;
  if not Exists (F3) then Fatal ('Cannot Open '+F3+' as input file');

  for I := 1 to TLim do PA[I] := Nil;
  BBOpen (FV3,F3,'r',BuffIn); OffSet := 1    { default record offset }
end;  { Initialize }

procedure Sort_Recs (Left,Right : word);           { Lo-Hi QuickSort }
var Lower,Upper,Middle : Word;
    Pivot              : S80;
begin
  Lower := Left; Upper := Right; Middle := (Left+Right) Shr 1;
  Pivot := PA[Middle]^;
  repeat
    while PA[Lower]^ < Pivot do Inc(Lower);
    while Pivot < PA[Upper]^ do Dec(Upper);
    if Lower <= Upper then
      begin
        T := PA[Lower]^; PA[Lower]^ := PA[Upper]^; PA[Upper]^ := T;
        Inc (Lower); Dec (Upper)
      end;
  until Lower > Upper;
  if Left < Upper then Sort_Recs (Left, Upper);
  if Lower < Right then Sort_Recs (Lower, Right)
end;                                                  { Sort_Recs }

procedure Display_Page (F,L : integer);
Var N,M : integer;
begin
  ClrScr; M := 0;
  for N := F to L do
    begin
      Inc (M); FastWrite (1,M,HiNorm,Copy(PA[N]^,OffSet,80))
    end
end;  { Display_Page }

procedure Do_Home;
begin
  B := 1; E := 20;
  if E > PAX then E := PAX
end;  { Do_Home }

procedure Check_End;
begin
  if E <= 0 then E := 1;
  if E > PAX then E := PAX;
  B := E-19;
  if B <= 0 then B := 1
end;  { Check_End }

function Get_Cmd : char;                         { Get User Command }
Var WCH : char;
begin
  WriteCenter (DSLine,LightGray,Black,'Cursor keys to move; Q or Esc to
Quit');
  WProm (LoNorm,'Command: '); WCH := ReadKey;{ fetch user keystroke }
  case WCH of
    #00 : begin                        { special/extended keystroke }
            WCH := ReadKey;
            case WCH of
              #71 : Do_Home;                                 { Home }
              #79 : E := PAX;                                 { End }
              #72 : Dec (E);                              { UpArrow }
              #73 : Dec (E,20);                              { PgUp }
              #80 : Inc (E);                            { DownArrow }
              #13,                                            { c/r }
              #81 : begin                                    { PgDn }
                      Inc (E,20); WCH := ' ';
                    end;
              #77 : begin                                 { RtArrow }
                      Inc (OffSet,10);
                      if OffSet > 71 then OffSet := 70
                    end;
              #75 : begin                               { LeftArrow }
                      Dec (OffSet,10);
                      if OffSet < 1 then OffSet := 1
                    end;
            end  { case }
          end;
    else
  end;  { case }
  Check_End; Get_Cmd := UpCase(WCH)
end;  { Get_Cmd }

procedure Read_Recs;
begin
  PAX := 0;
  while not EOF (FV3) do
    begin
      readln (FV3,S1); Inc (CT); FastWrite (1,DSLine,LoNorm,FSI(CT,5));
      CH := S1[1]; S2 := TTB(S1); Inc (PAX);
      if PAX <= TLim then
        begin
          New (PA[PAX]); PA[PAX]^ := S2;
          FastWrite (7,DSLine,LoNorm,FSI(PAX,4))
        end
    end;
  FastWrite (50,25,LoNorm,FSI(MemAvail,1)+' Bytes with data loaded');
  Close (FV3); Dispose (BuffIn);
  Sort_Recs (1,PAX);
  Done := false; Do_Home;               { set up 1st page of display }
  repeat                { display "pages" of data, using cursor keys }
    Display_Page(B,E);
    CH := Get_Cmd; Done := CH in [#27,'Q']
  until Done
end;  { Read_Recs }

begin  { Main Line }
  Initialize;                        { initialize system & variables }
  Read_Recs;                            { read & store records, list }
  WriteCenter (ErLine,LightGray,Black,'Finis...'); Pause
end.



Wed, 18 Jun 1902 08:00:00 GMT  
 Scrolling text file

Quote:
>I am looking for a way to scroll through a text file (in DOS) using
TP
>6.  I am able to view the file but I want to be able to scroll up and
>down through the file if it is bigger than one screen.  Please any
>advice is appreciated.

Hey there..  I can think of two ways..  One, which is how ansi smooth
scrolling is done, is to load the whole file into video memory
(starting at B800 i belive), and then scroll through the memory..  Or
you could do it how I did it my very first time and load it into an
array and scroll through the array..

Does anyone know any other methods?

Thakns
Bobby



Wed, 18 Jun 1902 08:00:00 GMT  
 Scrolling text file
On Thu, 15 Apr 1999 08:25:09 -0400, Dragonmyst

Quote:

>I am looking for a way to scroll through a text file (in DOS) using TP
>6.  I am able to view the file but I want to be able to scroll up and
>down through the file if it is bigger than one screen.  Please any
>advice is appreciated.

program   longtext;
uses      crt,dos;
const     ly=22;   (* <23   *)
          lx=79;   (* <80   *)
var       f:text;
          s,n:string;
          dir:DirStr;
          name:NameStr;
          ext:ExtStr;
          i,j,k,l,p:longint;
          c:char;
          x,max,dx,dy:byte;
begin
          dx:=0;  dy:=0;
          writeln;
          if ParamCount>0 then
             n:=paramStr(1)
          else begin
             write('Nome File: ');
             readln(n);
          end;
          writeln;
          if n<>'' then begin
             assign(f,n);
             {$I-}
             reset(f);
             {$I+}
             if IOResult=0 then begin
                l:=0;
                max:=0;
                while not eof(f) do begin
                   readln(f,s);
                   if length(s)>max then max:=length(s);
                   inc(l)
                end;
                reset(f);
                k:=0;
                x:=1;
                c:=#0;
                if length(n)>30 then begin
                   FSplit(n,dir,name,ext);
                   n:=name+ext;
                   n:=copy(n,1,30)
                end;
                while length(n)<30 do
                   n:=n+' ';
                repeat
                   ClrScr;
                   TextColor(0);  TextBackGround(7);
                   write(' File: ',n,'  ');
                   p:=(l div ly);
                   if (l mod ly)>0 then inc(p);
                   write('Pagina',(k div ly)+1:4,' di',p:4,'     ');
                   write(' <Esc> per uscire  ');
                   TextColor(7);  TextBackGround(0);
                   for j:=1 to ly do begin
                       gotoxy(lx+dx+1,j+dy+1);
                       if j=trunc((ly*k)/l)+1 then
                          write('2')
                       else
                          write('')
                   end;
                   for j:=1 to lx do begin
                       gotoxy(dx+j,ly+dy+2);
                       if j=trunc((lx*x)/max)+1 then
                          write('2')
                       else
                          write('')
                   end;
                   if (c<>#80) then begin
                      reset(f);
                      for j:=1 to k do
                          readln(f,s);
                   end;
                   i:=0;
                   while not eof(f) and (i<ly) do begin
                      inc(i);
                      readln(f,s);
                      s:=copy(s,x,lx);
                      for j:=1 to length(s) do
                          if not (s[j] in [#32..#254]) then
                             s[j]:=' ';
                      gotoxy(dx+1,dy+i+1);
                      write(s)
                   end;
                   repeat
                      c:=readkey;
                      if c=#0 then c:=readkey;
                      if (c=#77) and ((x+lx)<max) then x:=x+lx;
                      if (c=#75) and (x>lx) then x:=x-lx;
                      if (eof(f)) and (c=#80) then c:=#0
                   until c in [#27,#72,#80,#75,#77];
                   if c=#80 then k:=k+ly;
                   if (c=#72) and (k>0) then k:=k-ly;
                until c=#27;
                close(f);
                ClrScr
             end
             else
                writeln(#7,'File not present')
          end;
          writeln
end.

bye
--



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Scrolling Text in Text Mode - PLEASE HELP!

2. Unix Text File ---> DOS Text File

3. Converting Non-Text File to Text File

4. Not in graphics mode scrolling text box?

5. text scrolling

6. Smooth Text Scroll Help?

7. scrolling in text mode

8. Smooth Text Scroll Help?

9. Scrolling text up and down

10. scrolling in text mode

11. SCROLLING BOXES IN TEXT MODE

12. Qu: Javascript-like scrolling text in TP7?

 

 
Powered by phpBB® Forum Software