Board index » delphi » longer than 255 char strings?

longer than 255 char strings?

is it possible to make strings longer than 255 chars long? If so how?
 

Re:longer than 255 char strings?


Quote
Barry Robison (emper...@aol.com) wrote:

: is it possible to make strings longer than 255 chars long? If so how?

TYPE
   Charray = ARRAY [1..MaxInt] OF CHAR;
   LString = RECORD
      length : INTEGER;
      lstrng : Charray;
   END;

Re:longer than 255 char strings?


On 29 Sep 1995, Janos Szamosfalvi wrote:

Quote
> Barry Robison (emper...@aol.com) wrote:
> : is it possible to make strings longer than 255 chars long? If so how?

> TYPE
>    Charray = ARRAY [1..MaxInt] OF CHAR;
>    LString = RECORD
>       length : INTEGER;
>       lstrng : Charray;
>    END;

Shouldn't that be

  CHArray = [1..65535] of char; {use 1 to make it behave like regular strings}
  LString = Record
    len : word;
    str : ^Charray;
   end;

so that it doesn't take up the whole data segment and you can make it
65535 chars long, not 32767?

In any case, to use it like this, say you've got:

var
  str : LString;

begin
  str.len := 962; {or whatever length}
  getmem (str.str, str.len);

  {mess with it a bit}

  freemem (str.str, str.len);
end.

Of course, you need to be really careful about changing your lengths, etc...

____________________________________________________________________
Joshua Shagam\___  EMail: JSha...@nmsu.edu \__ "Reasoning depends on\______
207 Alumni Avenue\__ IRC: Kvantti on #coders  \___________ programming, not\
Las Cruces, NM 88003\___ WWW: HTTP://web.nmsu.edu/~jshagam\_on hardware."  /
United States of America\ Demoscene Alias: Quantum Porcupine\  -- Frank   /
/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\___ Herbert/
Check out my webpage for the Quantum Porcupine Archive, of course\______/

Re:longer than 255 char strings?


On 28 Sep 95 at 19:41, emper...@aol.com wrote:

Quote
> is it possible to make strings longer than 255 chars long? If so how?

Borland Pascal 7.0 has a built in feature for that: it is able to
produce and to handle zero-terminated strings (ASCIZ strings), such
as C or C++. The STRINGS unit implements a lot of functions around this.

If you don't use Version 7, here's how the ASCIZ string system works:
For each string, you have a couple of chars. The end of the string is
marked with a byte valued zero. The string does not have a length
indicator at it's beginning.

Stephan

+-----------------------------------------------------------------------+
| "...oh well, whatever, nevermind."                Nirvana/Kurt Cobain |
+-----------------------------------------------------------------------+

Re:longer than 255 char strings?


Hello All!

 KP> @RFC.Gate: Sat, 30 Sep 95 20:01:33

 KP> From: Kvantti Piikkisika <jsha...@nmsu.edu>

 KP> On 29 Sep 1995, Janos Szamosfalvi wrote:

 >> Barry Robison (emper...@aol.com) wrote:
 >> : is it possible to make strings longer than 255 chars long? If so how?
 >>
 >> TYPE
 >> Charray = ARRAY [1..MaxInt] OF CHAR;
 >> LString = RECORD
 >> length : INTEGER;
 >> lstrng : Charray;
 >> END;
 >>

 KP> Shouldn't that be

 KP>   CHArray = [1..65535] of char; {use 1 to make it behave like regular
 KP> strings}
 KP>   LString = Record
 KP>     len : word;
 KP>     str : ^Charray;
 KP>    end;

 KP> so that it doesn't take up the whole data segment and you can make it
 KP> 65535 chars long, not 32767?

 KP> In any case, to use it like this, say you've got:

 KP> var
 KP>   str : LString;

 KP> begin
 KP>   str.len := 962; {or whatever length}
 KP>   getmem (str.str, str.len);

 KP>   {mess with it a bit}

 KP>   freemem (str.str, str.len);
 KP> end.

You could write another Freemem. Fx a FreeMyMem(par);
which could free up the variable claim on HEAP, I think it could be done with
something like:
PROCEDURE MyFREEMEM(p:POINTER);
BEGIN
  FREEMEM(p^,p^.Size);
END;

All the types you define yourself always have a field called Size, so it will
be possible for this procedure to release the right amount of memory for the
specific type. Also it should not matter what type you've made as long as you
do not pass on any Pascal types.

 KP> Of course, you need to be really careful about changing your lengths,
 KP> etc...

Yup, chaning the Size (in your case Len) field after allocation is a no-no.

Regards
Mikkel Breiler

Re:longer than 255 char strings?


No, you can't directly have string longer than 255 characters. You have to use
either PChar from BP7.0 or higher or use an array. It is better to use PChar
because you don't have to define a set of functions to concat, or compare
string. Mind you that the PChar is a null-terminated string(same as C). I think
that Borland is trying to immitate the C style string in PChar, because the
functions concerning PChar (in the strings unit) have the same name as those in
C. YOu can read the help for more information about PChar.

If you want to use array, you should write your own functions yourself. And it
may not be so convenient.
--
____________________________________________________________________________
       o   \ o /  _ o         __|    \ /     |__        o _  \ o /   o    
      /|\    |     /\   __\o    \o    |    o/    o/__   /\     |    /|\  
      / \   / \   | \  /)  |    ( \  /o\  / )    |  (\  / |   / \   / \  
____________________________________________________________________________
 "--     | /     |       "--     "--                                  /\/\
 |       |=      |       |--     |--    email:h9504...@hkusua.hku.hk   /\
 \__     | \     \__     \__     \__                                   \/
____________________________________________________________________________

Re:longer than 255 char strings?


Quote
Kvantti Piikkisika (jsha...@nmsu.edu) wrote:

: On 29 Sep 1995, Janos Szamosfalvi wrote:

: > Barry Robison (emper...@aol.com) wrote:
: > : is it possible to make strings longer than 255 chars long? If so how?
: >
: > TYPE
: >    Charray = ARRAY [1..MaxInt] OF CHAR;
: >    LString = RECORD
: >       length : INTEGER;
: >       lstrng : Charray;
: >    END;
: >
: Shouldn't that be

:   CHArray = [1..65535] of char; {use 1 to make it behave like regular strings}
:   LString = Record
:     len : word;
:     str : ^Charray;
:    end;

Makes very little difference because you can later put LString into
the heap.  

: so that it doesn't take up the whole data segment and you can make it
: 65535 chars long, not 32767?

Personally, I don't  remember a single instance when I needed a string
longer than a couple of thousand character.   And in those instances
when STRING[255] was insufficient I used a linked list containing
STRING[80]'s.

Re:longer than 255 char strings?


In article <44vjbf$...@nntp5.u.washington.edu>, sza...@saul6.u.washington.edu
says...
Quote

>Kvantti Piikkisika (jsha...@nmsu.edu) wrote:
>: On 29 Sep 1995, Janos Szamosfalvi wrote:

>: > Barry Robison (emper...@aol.com) wrote:
>: > : is it possible to make strings longer than 255 chars long? If so how?
>: >
>: > TYPE
>: >    Charray = ARRAY [1..MaxInt] OF CHAR;
>: >    LString = RECORD
>: >       length : INTEGER;
>: >       lstrng : Charray;
>: >    END;
>: >
>: Shouldn't that be

>:   CHArray = [1..65535] of char; {use 1 to make it behave like regular
strings}
>:   LString = Record
>:     len : word;
>:     str : ^Charray;
>:    end;

>Makes very little difference because you can later put LString into
>the heap.  

>: so that it doesn't take up the whole data segment and you can make it
>: 65535 chars long, not 32767?

>Personally, I don't  remember a single instance when I needed a string
>longer than a couple of thousand character.   And in those instances
>when STRING[255] was insufficient I used a linked list containing
>STRING[80]'s.

Seems like a waste of time to me. Not to criticize but using a linked list for
this type of thing seems like a lot of work for nothing. A linked list of
STRING[80] would be fine for storing strings in a text editor but adds a lot
of coding overhead for a simple string....

Re:longer than 255 char strings?


Quote
Terry Gaudet (tgau...@cam.org) wrote:

: >
: >Personally, I don't  remember a single instance when I needed a string
: >longer than a couple of thousand character.   And in those instances
: >when STRING[255] was insufficient I used a linked list containing
: >STRING[80]'s.
: >
: Seems like a waste of time to me. Not to criticize but using a linked list for
: this type of thing seems like a lot of work for nothing. A linked list of
: STRING[80] would be fine for storing strings in a text editor but adds a lot
: of coding overhead for a simple string....

Usually, those strings gets displayed at one time or another.
I think formatting issues are virtually non-existent if the strings
are preformatted while a string longer than 80 chars may not look
very neat on a standard 80x25 screen, or you need to do some formatting
which also adds some overhead.

Re:longer than 255 char strings?


I will soon be uploading to ga...@uwasa.fi a unit to handle
dynamically allocated and automatically resized strings of
up to some 64K characters. In two versions: with objects
and without. The OO version is complete and I have been
using it for a while. The version without objects is
almost finished. Remains the documentation. Source code
will be provided.

Other Threads