home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
JUILLET
/
FSTLCSTR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
2KB
|
49 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 253 of 292
From : Todd Holmes 1:152/5.0 29 Jun 93 23:55
To : Dj Murdoch
Subj : A Faster LoadCstr
────────────────────────────────────────────────────────────────────────────────
Heres a slightly faster LoadCstr. I'ld like you to note my use of
type conversions to (quickly??) INC/DEC var of type pointer.
Warning, this function by-passes standard pascals strict type checking.
in other words, the lack (or addtion) of a simple little '^' (carrot)
can send your program off to ... well, just about anywhere :) and yes,
I do speak from experiance.}
Function LoadCStr(Var S:TStream): PChar; {Ver .03}
{Implemented quick type conversion to directly INC/DEC variables of
Type Pointer. If you have the Unit: CSTR ver .02, then replace the old
LoadCstr with this new Funtion}
var
Buff_Head:PChar; {Head: as in read/write head, to access the resizable
Array}
begin
Buff_Head := PChar(Longint(CStrBuff)-1); {CStrBuff is a resizable Array}
{Buff_Head now points to 1 byte before CStrBuff}
Repeat {Scan for end of string, (nul term char: #0)}
IncP(Buff_Head)); {Heres how to increase a Pointer Var}
S.Read(Buff_Head^,1); {Read straight to buffer}
Until (Buff_Head^ = #0) or
(Longint(Buff_Head) = MaxStrLen) or (S.Status <> StOk);
If Longint(Buff_Head) = MaxStrLen then
Buff_Head^ := #0; {Truncate to MaxStrLen}
LoadCstr := StrNew(CStrBuff); {Strings Unit: Makes copy of String
in CstrBuff}
end; {LoadCstr}
{in addtion are two Procedures to Directly INC/DEC var of type pointer, the
main purpose for INC/DEC pointers, is for Indexing resizable arrays,
(see Unit CStr) something that standard pascal is missing.}
Procedure IncP(Var P:Pointer);
begin
Inc(Longint(P));
end;
Procedure DecP(Var P:Pointer);
begin
Dec(Longint(P)):
end;