Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Delphi] String Help Needed!

10 views
Skip to first unread message

Smart Practice

unread,
Jun 20, 1995, 3:00:00 AM6/20/95
to
I am currently working on a project that needs to create dynamic strings
that are longer than 255 characters.

Now since I haven't worked with Pascal in a while, I'm not sure what to do.

I understand that I can define an array of characters longer than 255:

var
Test :array[1..1000] of Char;

But how do I assign text to it.

Test := 'This is a test!';
or
Test := SomeStringVariable;

both return "Error 26: Type Mismatch" errors.

Now I read I can also do:

var
Test :array[1..1000] of Char;
Test2 :PChar;
begin
Test2 := Test;
Test2 := 'This is a test';
end;

Now this works, but this doesn't:

var
Test :array[1..1000] of Char;
Test2 :PChar;
begin
Test2 := Test;
Test2 := SomeStringVariable;
end;

And again, this returns "Error 26: Type Mismatch".

Please help!

Thanks,

Lon D. Varscsak

Lloyd

unread,
Jun 22, 1995, 3:00:00 AM6/22/95
to

Look into TStringList and its ADD() method.

Lloyd

Danny

unread,
Jun 23, 1995, 3:00:00 AM6/23/95
to
smar...@news.enet.net (Smart Practice) wrote:
>
> I am currently working on a project that needs to create dynamic strings
> that are longer than 255 characters.
>

Try using StrPCopy to copy Pascal style strings to PChar variables.

Jeroen Pluimers

unread,
Jun 23, 1995, 3:00:00 AM6/23/95
to

Tuesday June 20 1995 18:27, smar...@news.enet.net wrote:

> I am currently working on a project that needs to create dynamic strings
> that are longer than 255 characters.

If you need these longer strings, then you need to use PChars. These are
equivalent to the C-style ASCIIZ strings. That means you also will have all the
coding overhead to perform actions (assign/copy/search) on them. Also, you need
conversion from Pascal-Style strings to PChar strings.

Delphi includes a lot of the functions you need in the SysUtils unit.

PChars are equivalent to zero-based arrays of character, so it's not


> var
> Test :array[1..1000] of Char;

But

var
Test: array[0..1000] of Char

> Test := 'This is a test!';

Should be replaced by


StrCopy (Test, 'This is a test');

> Test2 := SomeStringVariable;

Should be replaced by:

StrPCopy (Test, SomeStringVariable).


Jeroen


Richard MacDonald

unread,
Jun 29, 1995, 3:00:00 AM6/29/95
to
In <3scqtn$e...@druid.borland.com> Lloyd <llink...@wpo.borland.com>
writes:
>
>smar...@news.enet.net (Smart Practice) wrote:
>>
>> I am currently working on a project that needs to create dynamic strings
>> that are longer than 255 characters.
>>
>> Now since I haven't worked with Pascal in a while, I'm not sure what to
do.
>>
>> I understand that I can define an array of characters longer than 255:
>>
>> var
>> Test :array[1..1000] of Char;
>>
>> But how do I assign text to it.
>>
>> Test := 'This is a test!';
>> or
>> Test := SomeStringVariable;
>>
>> both return "Error 26: Type Mismatch" errors.
>>
>> Now I read I can also do:
>>
>> var
>> Test :array[1..1000] of Char;
>> Test2 :PChar;
>> begin
>> Test2 := Test;
>> Test2 := 'This is a test';
>> end;
>>
>> Now this works, but this doesn't:
>>
>> var
>> Test :array[1..1000] of Char;
>> Test2 :PChar;
>> begin
>> Test2 := Test;
>> Test2 := SomeStringVariable;
>> end;
>>
>> And again, this returns "Error 26: Type Mismatch".
>>
>> Please help!
>>
>> Thanks,
>>
>> Lon D. Varscsak
>
>Look into TStringList and its ADD() method.
>
>Lloyd

Note that because of the format of a Turbo/Borland/Delphi String
variable, it is impossible to create a string longer than 255
charaacters. The length of the string is contained as an unsigned
binary value in the first byte of the string. Thus the maximum string
size of 255. Since you can use a PCHAR to replace most strings, you
should probably use one for this. They have no fixed maximum size.

Dick

0 new messages