?
Solved

About pointers (basics)

Posted on 2004-04-11
1
Medium Priority
?
172 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 300 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
New style of hardware planning for Microsoft Exchange server.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 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