Board index » delphi » TMemo.SetTextBuf not working with PChar

TMemo.SetTextBuf not working with PChar

I'm back with my favorite problem, how to get a TMemo to show 4,000
characters.

I am loading a PChar from a file (using Fileseek to get to the middle, and
BlockRead to load the PChar).  When I look at the PChar, all looks fine.

However, when I use the following two commands (in line, one after the
other, just like you see them here):

          Memo1.SetTextBuf(LoadTextString);
          Memo2.Text:=StrPas(LoadTextString);

Memo1 only sometimes shows the information, while Memo2 always shows the
first 255 (since it is grabbing the Pascal string version).  What is wrong
with this picture?

I suspect that I need a primer on PChars ... but the Delphi docs and
on-line help are worth less than nothing, since they purport to explain
the difference between PChars and strings, but all the examples are 10-20
characters long.

Any help would be greatly appreciated - e-mail or post.

Thanks!

 

Re:TMemo.SetTextBuf not working with PChar


Quote
MARATHON99 (maratho...@aol.com) wrote:

: I am loading a PChar from a file (using Fileseek to get to the middle, and
: BlockRead to load the PChar).  When I look at the PChar, all looks fine.

:           Memo1.SetTextBuf(LoadTextString);
:           Memo2.Text:=StrPas(LoadTextString);

: Memo1 only sometimes shows the information, while Memo2 always shows the
: first 255 (since it is grabbing the Pascal string version).  What is wrong
: with this picture?
The problem in the second case is clear - the text property is of the type
string which can only hold 255 chars, so everything behind is throwed away
(this is done by the pchar->string conversion with strpas() ). But the first
one should work as long as the LoadTextString is a valid pchar - sure you
haven't forgot the null termination.

: I suspect that I need a primer on PChars ... but the Delphi docs and
: on-line help are worth less than nothing, since they purport to explain
: the difference between PChars and strings, but all the examples are 10-20
: characters long.
Maybe because examples with long texts would hide the essential part of the
example behind hundred of irrelevant characters :-) In all the pchar
examples you can always think of them as extendable up to 64k/255k/4G or
whatever the limit of pchars is.

Bye,
   Andy

--
----------------------------------------------------------------------------
Andreas H"orstemeier                       | "If Saddam Hussein had said he
                                           | was doing a school project on
email: hoer...@hal1.physik.uni-dortmund.de | Kuweit, he'd have found life a
       a...@farpoint.sauerland.de          | lot easier..."
fido:      2:2444/4505.3                   |     (Terry Pratchett, 'Johnny
astronet:  122:490/1.53                    |                  and the dead')  
----------------------------------------------------------------------------

Re:TMemo.SetTextBuf not working with PChar


Quote
>I am loading a PChar from a file (using Fileseek to get to the middle, and
>BlockRead to load the PChar).  When I look at the PChar, all looks fine.

>However, when I use the following two commands (in line, one after the
>other, just like you see them here):

>          Memo1.SetTextBuf(LoadTextString);
>          Memo2.Text:=StrPas(LoadTextString);

        Well, this should work if the PChar has had enough memory allocated, etc.
What are you doing to "look at" the PChar to determine that it looks fine?

        Oh: Could it be that LoadTextString contains a null (#0) and the SetTextBuf
is stopping there, but whatever you're using to look at the PChar is showing you
the whole thing includeing the part past the null?

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Other Threads