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
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
FpDebug breakpoint on "be...
by
440bx
[
Today
at 09:46:38 pm]
Poll: Watches and Display...
by
440bx
[
Today
at 07:13:51 pm]
Lazarus for Windows on aa...
by
msintle
[
Today
at 06:42:18 pm]
InstallAware Using Lazaru...
by
marcov
[
Today
at 04:46:46 pm]
Who is Indy mattias?
by
paweld
[
Today
at 04:17:53 pm]
[solved] how to get class...
by
Joanna
[
Today
at 03:53:05 pm]
I just released a commerc...
by
BrassGear
[
Today
at 03:17:28 pm]
Does anyone know why thes...
by
Laksen
[
Today
at 03:04:14 pm]
Database standards OR Am ...
by
gidesa
[
Today
at 02:37:56 pm]
How to: create DLL file f...
by
TRon
[
Today
at 02:26:53 pm]
A fairly simple sound sol...
by
paweld
[
Today
at 01:46:11 pm]
Demoscene The Champs Crac...
by
KodeZwerg
[
Today
at 01:45:18 pm]
Access violation when ope...
by
Чебурашка
[
Today
at 12:27:34 pm]
Step-into the field sette...
by
Martin_fr
[
Today
at 11:31:48 am]
Access violation when re-...
by
Chris Osborne
[
Today
at 11:31:25 am]
AI, NLP and CAI: Text Gen...
by
Dzandaa
[
Today
at 11:03:26 am]
dwindows for Android
by
PierceNg
[
Today
at 10:54:44 am]
create system unit from s...
by
Laksen
[
Today
at 10:53:57 am]
[Solved] Find child contr...
by
Joanna
[
Today
at 09:53:43 am]
FpDebug unexpected Assemb...
by
Marc
[
Today
at 08:46:38 am]
Offical launch of the 1 B...
by
Handoko
[
Today
at 07:59:07 am]
Big Numbers Math
by
iLya2IK
[
Today
at 07:13:20 am]
BUG REPORT: Unable to gen...
by
dbannon
[
Today
at 06:29:49 am]
what to do if my target M...
by
Laksen
[
Today
at 12:49:12 am]
For-in loop over constant...
by
ASerge
[
Today
at 12:36:09 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Showmessage MessageBox MessageDlg long string (Read 14283 times)
k1attila1
Full Member
Posts: 105
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: 5154
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: 2242
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: 5154
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: 105
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: 105
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: 1830
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
k1attila1
Full Member
Posts: 105
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