Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
LCL
»
Showmessage MessageBox MessageDlg long string
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Why does Free Pascal use ...
by
Thaddy
[
Today
at 08:51:27 am]
Proper name for free meth...
by
Thaddy
[
Today
at 08:28:56 am]
Font Name properties
by
creaothceann
[
Today
at 07:12:12 am]
TlsLib4Pascal
by
Thaddy
[
Today
at 07:04:33 am]
BS Controls – Silly Compo...
by
Xenno
[
Today
at 06:53:52 am]
Adding persistent fields ...
by
paweld
[
Today
at 06:11:57 am]
QGradientTrackPanel: A Fu...
by
Ed78z
[
Today
at 01:24:17 am]
Solved: Picture Framer (R...
by
Boleeman
[
Today
at 12:20:27 am]
Lazarus Vs Codetyphon
by
BSaidus
[August 16, 2026, 09:59:46 pm]
MR - DebuggerIntf for ter...
by
Martin_fr
[August 16, 2026, 08:21:29 pm]
Is it possible to communi...
by
Warfley
[August 16, 2026, 08:15:43 pm]
array values as reference
by
jamie
[August 16, 2026, 07:58:57 pm]
LRS Explorer
by
Xenno
[August 16, 2026, 07:27:54 pm]
[Solved] The use of EXIT ...
by
440bx
[August 16, 2026, 07:27:20 pm]
TEDit PasswordChar not wo...
by
Hansaplast
[August 16, 2026, 05:19:01 pm]
Which Linux version
by
cdbc
[August 15, 2026, 08:28:37 pm]
[Qt5/Qt6] JPSupport-Qt: J...
by
shortcut
[August 15, 2026, 08:19:29 pm]
FpDebug: Bugs and API gap...
by
Martin_fr
[August 15, 2026, 08:07:50 pm]
Synedit wordwrap
by
Martin_fr
[August 15, 2026, 05:37:57 pm]
Unleashed Pascal (async/a...
by
chamfay
[August 15, 2026, 10:35:09 am]
TDWEdit
by
docno
[August 15, 2026, 10:12:10 am]
var vs out (including "co...
by
440bx
[August 15, 2026, 08:42:28 am]
Local AI LLM Wrapper Demo...
by
edwinyzh
[August 15, 2026, 05:30:15 am]
Trndi 16 is released
by
slicke
[August 15, 2026, 03:06:44 am]
Clean up and build
by
n7800
[August 14, 2026, 11:03:28 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Showmessage MessageBox MessageDlg long string (Read 16449 times)
k1attila1
Full Member
Posts: 109
Showmessage MessageBox MessageDlg long string
«
on:
April 20, 2017, 07:08:45 pm »
Hello
Showmessage, MessageBox, MessageDlg wrap/break the line if string is long (eg 100 char)
Does anybody know any solution or it is OS problem (Win10) ?
thank you Attila
«
Last Edit: April 21, 2017, 04:36:42 pm by k1attila1
»
Logged
Handoko
Hero Member
Posts: 5559
My goal: build my own game engine using Lazarus
Re: Showmessage MessageBox MessageDlg long string
«
Reply #1 on:
April 20, 2017, 08:04:48 pm »
Tested ShowMessage's wrapping behavior on Lazarus 1.6.4 FPC 3.0.2 on my Ubuntu Mate 16.10 computer. And this is the test result:
- The message will be wrapped on char 32 if the line is too long.
- The message won't be wrapped nor truncated even it exceeds my screen width, if the string doesn't contain space (chr 32).
This is the code I used:
Code: Pascal
[Select]
[+]
[-]
unit
Unit1
;
{$mode objfpc}{$H+}
interface
uses
Classes
,
SysUtils
,
Forms
,
Controls
,
Dialogs
,
StdCtrls
;
type
{ TForm1 }
TForm1
=
class
(
TForm
)
Button1
:
TButton
;
procedure
Button1Click
(
Sender
:
TObject
)
;
private
{ private declarations }
public
{ public declarations }
end
;
var
Form1
:
TForm1
;
implementation
{$R *.lfm}
{ TForm1 }
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
var
i
:
Integer
;
S
:
string
;
begin
S
:
=
''
;
for
i
:
=
1
to
20
do
S
:
=
S
+
IntToStr
(
i
)
+
'-123456 '
;
// has chr 32
ShowMessage
(
S
)
;
S
:
=
''
;
for
i
:
=
1
to
20
do
S
:
=
S
+
IntToStr
(
i
)
+
'-123456x'
;
// no chr 32
ShowMessage
(
S
)
;
end
;
end
.
«
Last Edit: April 20, 2017, 08:57:21 pm by Handoko
»
Logged
ASerge
Hero Member
Posts: 2514
Re: Showmessage MessageBox MessageDlg long string
«
Reply #2 on:
April 20, 2017, 08:36:52 pm »
Quote from: k1attila1 on April 20, 2017, 07:08:45 pm
Does anybody know any solution or it is OS problem (Win10) ?
What is solution?
My test. Windows 7 x64.
Dialogs.ShowMessage, Application.MessageBox, Dialogs.MessageDlg wrap after 59 chars if text contain space, or show 56 chars with '...' on single line without wrap.
Windows.MessageBox always wrap text. After 73 chars or early, if text contain space.
Logged
Handoko
Hero Member
Posts: 5559
My goal: build my own game engine using Lazarus
Re: Showmessage MessageBox MessageDlg long string
«
Reply #3 on:
April 20, 2017, 08:53:12 pm »
So the ShowMessage's behavior is OS depended. My test never got a '...' even the string's length is 491 (for i := 1 to 50).
«
Last Edit: April 20, 2017, 08:58:42 pm by Handoko
»
Logged
k1attila1
Full Member
Posts: 109
Re: Showmessage MessageBox MessageDlg long string
«
Reply #4 on:
April 21, 2017, 05:34:16 am »
Thank You
So it is OS problem and not Lazarus.
Thank You again Attila
Logged
balazsszekely
Guest
Re: Showmessage MessageBox MessageDlg long string
«
Reply #5 on:
April 21, 2017, 06:34:52 am »
Hi Attila,
Try the following code, it works on my win10:
Code: Pascal
[Select]
[+]
[-]
function
MessageDlgEx
(
const
AMsg
:
string
;
ADlgType
:
TMsgDlgType
;
AButtons
:
TMsgDlgButtons
;
AParent
:
TForm
)
:
TModalResult
;
var
MsgFrm
:
TForm
;
begin
MsgFrm
:
=
CreateMessageDialog
(
AMsg
,
ADlgType
,
AButtons
)
;
try
MsgFrm
.
Position
:
=
poDefaultSizeOnly
;
MsgFrm
.
FormStyle
:
=
fsSystemStayOnTop
;
MsgFrm
.
Left
:
=
AParent
.
Left
+
(
AParent
.
Width
-
MsgFrm
.
Width
)
div
2
;
MsgFrm
.
Top
:
=
AParent
.
Top
+
(
AParent
.
Height
-
MsgFrm
.
Height
)
div
2
;
Result
:
=
MsgFrm
.
ShowModal
;
finally
MsgFrm
.
Free
end
;
end
;
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
begin
MessageDlgEx
(
'fadfa afdfad afdad fafsd faf af af ads dddddddddddddddddddddddd dddddddddddddddddddddddd dddddddddddddddddddddddd dafdsad fasdfa daf'
,
mtInformation
,
[
mbOk
]
,
Form1
)
;
end
;
Logged
k1attila1
Full Member
Posts: 109
Re: Showmessage MessageBox MessageDlg long string
«
Reply #6 on:
April 21, 2017, 07:16:21 am »
Thank you , Sir !
It is a good solution.
Attila
Logged
Zoran
Hero Member
Posts: 1993
Re: Showmessage MessageBox MessageDlg long string
«
Reply #7 on:
April 21, 2017, 08:47:55 am »
Another solution is to replace spaces with
non-breaking spaces
:
Code: Pascal
[Select]
[+]
[-]
const
NonBreakingSpace
:
String
=
Char
(
$C2
)
+
Char
(
$A0
)
;
// non-breaking space (utf8-encoded)
procedure
MyShowMessage
(
const
aMsg
:
String
)
;
begin
ShowMessage
(
StringReplace
(
aMsg
,
Char
(
32
)
,
NonBreakingSpace
,
[
rfReplaceAll
]
)
)
;
end
;
function
MyMessageDlg
(
const
aMsg
:
string
;
DlgType
:
TMsgDlgType
;
Buttons
:
TMsgDlgButtons
;
HelpCtx
:
Longint
)
:
TModalResult
;
begin
Result
:
=
MessageDlg
(
StringReplace
(
aMsg
,
Char
(
32
)
,
NonBreakingSpace
,
[
rfReplaceAll
]
)
,
DlgType
,
Buttons
,
HelpCtx
)
;
end
;
EDIT: No, GetMem's solution is better, as line breaking occurs not only on spaces, but also on other charactes which can appear in your message (dashes, tabs, ...), and these aren't handled by my code.
«
Last Edit: April 21, 2017, 09:10:38 am by Zoran
»
Logged
Swan, ZX Spectrum emulator
https://github.com/zoran-vucenovic/swan
k1attila1
Full Member
Posts: 109
Re: Showmessage MessageBox MessageDlg long string
«
Reply #8 on:
April 21, 2017, 11:07:14 am »
Thank you Zoran !
I study your solution too ,maybe useful for another problem.
Attila
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
LCL
»
Showmessage MessageBox MessageDlg long string
TinyPortal
© 2005-2018