Solved

About pointers (basics)

Posted on 2004-04-11
1
171 Views
Last Modified: 2010-04-16
Hi everyone,

i'm following the online tutorial that is found on http://www.geocities.com/codeteacher/ i'm at the second lesson, chapter 1. In the previous lesson we had to write a program able to store a textfile in an array and then writing it on the screen. We had also to provide some "browse" features to allow the user to read the whole text using the arrow keys and the page and page down. I did it (may sound like very usual stuff for you but for me it's more dificult).
the program looks like the following

Procedure OpenReadme;
{Procedure that read the 400 first lines of the textfile into an array}
Procedure WriteHeader;
{Procedure that made a kind of menu bar above}
Procedure PageUp;
Procedure PageDown;
Procedure LinUp;
Procedure LineDown;
Procedure DisplayText;

in the Procedure DisplayText there is somehting like this

TempChar:=Readkey
CASE Ord(TempChar) OF
 85:PageUp;
 48:PageDown;
 32:LineUp;
 25:LineDown;
End;

{Head Program}
BEGIN
 OpenReadme;
 WriteHeader;
 DisplayText;
END.

Well that is the shape of the program, it whole works.
but now in that lesson, we have to make the same program AND store the data using pointers. And that is were i'm stuck right now. I have no idea how i should store it in a pointer.

should i make a pointer-array ?

Type
 PText:^TText;
 TText:Array[1..400] Of String;
Var
 WholeText:PText;

??? no i can't do that because we have to allow the user to see the WHOLE text and not only the 400 first lines

i taught of another solution;
store line by line into a generic pointer, if i understood correctly generic pointer have no type, so it is like the 'variant' type in visual basic. i think it is possible, than we have one dynamic variable containing the whole text file, but how should i use that variable to display the text and allow browsing in it ???

CAN SOMEONE PLEASE HELP ME OUT OF THAT ???

Elvis
0
Comment
Question by:Elvis1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
xtremecris earned 100 total points
ID: 10801275
You could try something like this:
Type
 TText:array[1..100] Of PText;
 PText:^TText;
 TText:Array[1..400] Of String;

That means: there is an array of pointers to a TText structure which you can access more easily with an function like this:

function GetLine(Number:Integer):string;
begin
 GetLine:=TText[((Number-1) div 400)+1]^[((Number-1) mod 400)+1];
end;

You might not understand all the indices, they are correct but harder to explain(you should try with a piece of paper to figure them out for your self).

Everything would be a lot easier to understand and a lot faster and run-time if you do it like this:

Type
 tText : array[0..16383] Of ^String;

When you acces the line N from the file it's simply:
                   tText[N]^

This way you have little modifications to do to your original program and there are 16.384 lines of file in memory.This way it's safe to assume that you can read the whole file in memory, in fact if you use TPascal or BPascal you can't actually hope to read more then this.

If you have more questions don't hesitate to ask.

Best regards,
Cris.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question