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
Try using StrPCopy to copy Pascal style strings to PChar variables.
> 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
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