From 2adb97a92923320df23405fbe120f5e4d436802f Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 24 Aug 1999 13:14:50 +0000 Subject: [PATCH] * disposestr allocstr compatible with delphi --- rtl/objpas/syspch.inc | 46 +++++++++++++++++++++--------------------- rtl/objpas/syspchh.inc | 9 ++++++--- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/rtl/objpas/syspch.inc b/rtl/objpas/syspch.inc index 47a4668c43..01ae54e665 100644 --- a/rtl/objpas/syspch.inc +++ b/rtl/objpas/syspch.inc @@ -37,8 +37,8 @@ type function StrPas(Str: PChar): string; begin -SetLength(result, StrLen(Str)); -Move(Str^, result[1], Length(result)); + SetLength(result, StrLen(Str)); + Move(Str^, result[1], Length(result)); end ; { StrAlloc allocates a buffer of Size + 4 @@ -46,20 +46,19 @@ end ; StrDispose should be used to destroy the buffer } function StrAlloc(Size: cardinal): PChar; -var Temp: pointer; begin -GetMem(Temp, Size + SizeOf(cardinal)); -Move(Size, Temp^, SizeOf(cardinal)); -pbyte(Temp + SizeOf(cardinal))^ := 0; -result := PChar(Temp + SizeOf(cardinal)); -end ; + inc(size,sizeof(cardinal)); + getmem(result,size); + cardinal(pointer(result)^):=size; + inc(result,sizeof(cardinal)); +end; { StrPCopy copies the pascal string Source to Dest and returns Dest } function StrPCopy(Dest: PChar; Source: string): PChar; begin -result := StrMove(Dest, PChar(Source), length(Source)+1); + result := StrMove(Dest, PChar(Source), length(Source)+1); end ; { StrPLCopy copies MaxLen or less characters from the pascal string @@ -81,30 +80,31 @@ end ; { StrDispose clears the memory allocated with StrAlloc } -procedure StrDispose(var Str: PChar); -var Size: cardinal; +procedure StrDispose(Str: PChar); begin -if (Str <> Nil) then begin - Str := PChar(Str - SizeOf(cardinal)); - Move(Str^, Size, SizeOf(cardinal)); - FreeMem(Str, Size + SizeOf(cardinal)); - Str := Nil; - end ; -end ; + if (Str <> Nil) then + begin + dec(Str,sizeof(cardinal)); + Freemem(str,cardinal(pointer(str)^)); + end; +end; { StrBufSize returns the amount of memory allocated for pchar Str allocated with StrAlloc } -function StrBufSize(var Str: PChar): cardinal; +function StrBufSize(Str: PChar): cardinal; begin -if Str <> Nil then - result := Cardinal(pointer(Str - SizeOf(cardinal))^) -else + if Str <> Nil then + result := cardinal(pointer(Str - SizeOf(cardinal))^)-sizeof(cardinal) + else result := 0; end ; { $Log$ - Revision 1.5 1999-07-09 10:06:34 peter + Revision 1.6 1999-08-24 13:14:50 peter + * disposestr allocstr compatible with delphi + + Revision 1.5 1999/07/09 10:06:34 peter * merged Revision 1.4.2.1 1999/07/09 10:05:05 peter diff --git a/rtl/objpas/syspchh.inc b/rtl/objpas/syspchh.inc index 80ef6789f0..8100251b71 100644 --- a/rtl/objpas/syspchh.inc +++ b/rtl/objpas/syspchh.inc @@ -46,12 +46,15 @@ function StrPas(Str: PChar): string; function StrPCopy(Dest: PChar; Source: string): PChar; function StrPLCopy(Dest: PChar; Source: string; MaxLen: cardinal): PChar; function StrAlloc(Size: cardinal): PChar; -function StrBufSize(var Str: PChar): cardinal; -procedure StrDispose(var Str: PChar); +function StrBufSize(Str: PChar): cardinal; +procedure StrDispose(Str: PChar); { $Log$ - Revision 1.3 1999-02-25 07:39:58 michael + Revision 1.4 1999-08-24 13:14:51 peter + * disposestr allocstr compatible with delphi + + Revision 1.3 1999/02/25 07:39:58 michael * Joined strings and sysutils Revision 1.2 1998/09/16 08:28:41 michael