Solved

About pointers (basics)

Posted on 2004-04-11
1
165 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now