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
Slow copying of small str...
by
Nitorami
[
Today
at 09:43:56 am]
How to: create DLL file f...
by
paule32
[
Today
at 09:27:34 am]
Assign (textfile) not com...
by
dsiders
[
Today
at 08:51:13 am]
Text orientation in TMemo...
by
CM630
[
Today
at 08:41:53 am]
Linux Workspaces -- StayO...
by
AmatCoder
[
Today
at 08:21:27 am]
Demoscene The Champs Crac...
by
Lulu
[
Today
at 08:15:12 am]
Azure sql database will n...
by
paweld
[
Today
at 07:24:47 am]
Find child controls by na...
by
Handoko
[
Today
at 04:17:05 am]
location of non visual co...
by
VisualLab
[April 17, 2024, 11:58:55 pm]
For-in loop over constant...
by
Joanna
[April 17, 2024, 11:57:15 pm]
Lazarus editor feature re...
by
440bx
[April 17, 2024, 11:49:08 pm]
InstallAware Using Lazaru...
by
VisualLab
[April 17, 2024, 11:08:24 pm]
How would you define a fi...
by
wp
[April 17, 2024, 11:04:00 pm]
Directx9 with mylogo insi...
by
KodeZwerg
[April 17, 2024, 11:03:54 pm]
Lazarus for Windows on aa...
by
Wallaby
[April 17, 2024, 10:25:46 pm]
[SOLVED] TDbf table, Leve...
by
1HuntnMan
[April 17, 2024, 10:03:16 pm]
Doomed name
by
Martin_fr
[April 17, 2024, 09:09:52 pm]
lazarus-project_3.2.0-0_a...
by
midigark
[April 17, 2024, 06:09:40 pm]
TBGRABitmap.TextSize retu...
by
circular
[April 17, 2024, 05:24:04 pm]
BUG REPORT: Unable to gen...
by
gasensor
[April 17, 2024, 05:10:20 pm]
[solved]FP IDE(FP.exe) fa...
by
gasensor
[April 17, 2024, 04:45:40 pm]
Inherits forms and releas...
by
ASerge
[April 17, 2024, 03:37:45 pm]
The weird Rewrite bug
by
Kays
[April 17, 2024, 01:23:40 pm]
FpDebug unexpected Assemb...
by
440bx
[April 17, 2024, 12:54:43 pm]
Arabic text, problem on L...
by
Zaher
[April 17, 2024, 12:34:05 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Showmessage MessageBox MessageDlg long string (Read 14272 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: 5151
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: 2241
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: 5151
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