home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programming Unleashed
/
Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso
/
chap16
/
linklst1
/
linklst1.dpr
next >
Wrap
Text File
|
1995-03-20
|
2KB
|
108 lines
program LinkLst1;
{ Program copyright (c) 1995 by Charles Calvert }
{ Project Name: LINKLST1 }
uses
WinCrt;
type
PMyRecord = ^TMyRecord;
TMyRecord = Record
Name: String;
Next: PMyRecord;
end;
var
Total: Integer;
function Int2Str(L : LongInt) : string;
{ Converts an integer to a string for use with OutText, OutTextXY }
var
S : string;
begin
Str(L, S);
Int2Str := S;
end; { Int2Str }
procedure CreateNew(var Item: PMyRecord);
begin
New(Item);
Item^.Next := nil;
Item^.Name := '';
end;
procedure GetData(var Item: PMyRecord);
begin
Item^.Name := 'Sam' + Int2Str(Total);
end;
procedure DoFirst(var First, Current: PMyRecord);
begin
CreateNew(Current);
GetData(Current);
First := Current;
end;
procedure Add(var Current: PMyRecord);
var
Prev: PMyRecord;
begin
Prev := Current;
CreateNew(Current);
GetData(Current);
Prev^.Next := Current;
end;
{ Here is an alternate version of the Add procedure }
procedure Add2(var Current: PMyRecord);
var
Temp: PMyRecord;
begin
CreateNew(Temp);
GetData(Temp);
Current^.Next := Temp;
Current := Temp;
end;
procedure Show(Head: PMyRecord);
begin
while Head^.Next <> nil do begin
WriteLn(Head^.Name);
Head := Head^.Next;
end;
WriteLn(Head^.Name);
end;
procedure FreeAll(var Head: PMyRecord);
var
Temp: PMyRecord;
begin
while Head^.Next <> nil do begin
Temp := Head^.Next;
Dispose(Head);
Head := Temp;
end;
Dispose(Head);
end;
var
First,
Current: PMyRecord;
begin
HeapLimit := 0;
ClrScr;
WriteLn('Memavail = ', MemAvail);
Total := 1;
DoFirst(First, Current);
repeat
Inc(Total);
Add(Current);
until Total > 20;
Show(First);
FreeAll(First);
WriteLn('MemAvail = ', MemAvail);
ReadLn;
end.