Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2003-07

Patch for Win32 interface

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Smat

Hi,
attached patch adds LM_APPENDTEXT message used by TMemo. This message is called when a new line is added into a memobox.

But I have a problem when the memo is cleared (memo.text:=''). Allways
the firs line is not removed.

Martin Smat.

diff -c old\win32object.inc new\win32object.inc
*** old\win32object.inc Tue Jul 29 18:14:54 2003
--- new\win32object.inc Wed Jul 30 18:24:46 2003
***************
*** 409,414 ****
--- 409,420 ----
LM_ATTACHMENU:

        AttachMenu(Sender);
          //SH: think of TBitmap.handle!!!!

+ LM_APPENDTEXT:
+ Begin
+ PStr:=PChar((Sender as TMemo).Text);
+ StrCat(PStr, Data);
+ SetLabel(Sender, PStr);
+ End;
LM_SCREENINIT:

      Begin
        if Sender=nil then Handle := GetDesktopWindow

Reply by email

Martin Smat
to Marc Weustink: EEEEEEK ! Don't do this ! StrCat just concatinates 2 destination and source buffer and…

Marc Weustink napsal(a):

Show quoted text 55 lines
EEEEEEK ! At 18:37 30-7-2003 +0200, Martin Smat wrote: > Hi, > attached patch adds LM_APPENDTEXT message used by TMemo. This message > is called when a new line is added into a memobox. > > But I have a problem when the memo is cleared (memo.text:=''). Allways > the firs line is not removed. > > Martin Smat. > > > diff -c old\win32object.inc new\win32object.inc > *** old\win32object.inc Tue Jul 29 18:14:54 2003 > --- new\win32object.inc Wed Jul 30 18:24:46 2003 > *************** > *** 409,414 **** > --- 409,420 ---- > LM_ATTACHMENU: > AttachMenu(Sender); > //SH: think of TBitmap.handle!!!! > + LM_APPENDTEXT: > + Begin > + PStr:=PChar((Sender as TMemo).Text); > + StrCat(PStr, Data); > + SetLabel(Sender, PStr); Don't do this ! StrCat just concatinates 2 destination and source buffer and puts the result in the destination buffer. *without length checking* *without buffer allocation* what do we have: one casted string with enough room to hold itself used as destination and one buffer of data to be apended. what do we get: a nice bufferoverrun ! Just this weekend there was a discussion about the dos and donts concerning strings and pchars. This is don't ! Solution: use a string as temp buffer S := (Sender as TMemo).Text + PChar(Data); SetLabel(Sender, PChar(S)); Marc (update is in CVS)

Thank you for this correction. Next time I must be more carefull.

Martin.

Reply by email

Mattias Gaertner
to Martin Smat: attached patch adds LM_APPENDTEXT message used by TMemo. This message is called when a…
Hi, attached patch adds LM_APPENDTEXT message used by TMemo. This message is called when a new line is added into a memobox.

Thanks. Apllied.

But I have a problem when the memo is cleared (memo.text:=''). Allways the firs line is not removed.

TMemo needs some work anyway. The TStringList should be replaced by a TTextStrings. Any volunteers?

Mattias

Reply by email

Marc Weustink
to Martin Smat: attached patch adds LM_APPENDTEXT message used by TMemo. This message is called when a…

EEEEEEK !

Martin Smat wrote 24 lines
Hi, attached patch adds LM_APPENDTEXT message used by TMemo. This message is called when a new line is added into a memobox. But I have a problem when the memo is cleared (memo.text:=''). Allways the firs line is not removed. Martin Smat. diff -c old\win32object.inc new\win32object.inc *** old\win32object.inc Tue Jul 29 18:14:54 2003 --- new\win32object.inc Wed Jul 30 18:24:46 2003 *************** *** 409,414 **** --- 409,420 ---- LM_ATTACHMENU: AttachMenu(Sender); //SH: think of TBitmap.handle!!!! + LM_APPENDTEXT: + Begin + PStr:=PChar((Sender as TMemo).Text); + StrCat(PStr, Data); + SetLabel(Sender, PStr);

Don't do this !

StrCat just concatinates 2 destination and source buffer and puts the result in the destination buffer.

*without length checking*
*without buffer allocation*

what do we have: one casted string with enough room to hold itself used as destination and one buffer of data to be apended.

what do we get: a nice bufferoverrun !

Just this weekend there was a discussion about the dos and donts concerning strings and pchars. This is don't !

Solution: use a string as temp buffer

   S := (Sender as TMemo).Text + PChar(Data);
   SetLabel(Sender, PChar(S));

Marc (update is in CVS)

Reply by email