Recent

Author Topic: application.messagebox  (Read 20369 times)

nocuttree

  • New Member
  • *
  • Posts: 36
application.messagebox
« on: October 06, 2014, 12:43:29 pm »
I have problem with this code
s:='hello';
application.messagebox(s,'!!!',0);
How to fix it? Thanks!
Sorry my English, Windows xp, Lazarus 1.2.2!

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: application.messagebox
« Reply #1 on: October 06, 2014, 12:49:50 pm »
How to fix what?  Give us at least a small clue as to what's going wrong...

The following is guess that you're just trying to display text to the user...

Code: [Select]
Uses
  Dialogs
...

...
Var
  s: String;
Begin
  s:='hello';
  ShowMessage(s);
End;
« Last Edit: October 06, 2014, 12:51:34 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: application.messagebox
« Reply #2 on: October 06, 2014, 01:34:34 pm »
I guess nocuttree is complaining about the error message when compiling:
Code: [Select]
unit1.pas(xx,xx) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "PChar"

So, an immediate quick and dirty fix would be:
Code: [Select]
application.messagebox(pchar(s),'!!!',0);
or to use ShowMessage, as already proposed by Mike.Cornflake.

nocuttree

  • New Member
  • *
  • Posts: 36
Re: application.messagebox
« Reply #3 on: October 06, 2014, 05:53:15 pm »
I guess nocuttree is complaining about the error message when compiling:
Code: [Select]
unit1.pas(xx,xx) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "PChar"

So, an immediate quick and dirty fix would be:
Code: [Select]
application.messagebox(pchar(s),'!!!',0);
or to use ShowMessage, as already proposed by Mike.Cornflake.
How to fix what?  Give us at least a small clue as to what's going wrong...

The following is guess that you're just trying to display text to the user...

Code: [Select]
Uses
  Dialogs
...

...
Var
  s: String;
Begin
  s:='hello';
  ShowMessage(s);
End;
Thanks you very much!
Sorry my English, Windows xp, Lazarus 1.2.2!

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: application.messagebox
« Reply #4 on: October 07, 2014, 01:06:30 am »
Also, you can use my library: https://github.com/t-edson/MisUtils
and use:
* MsgBox() -> for showing messages
* MsgExc() -> for showing messages with the Exclamation Icon
* MsgErr() -> for showing messages with the Error Icon

Moreover, these procedures admit translation for other languages.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: application.messagebox
« Reply #5 on: October 07, 2014, 07:32:57 am »
As I always do- I recommend using QuestionDlg than anything else. Because one day you decide to make a multi-language app and you start replacing all Application.MessageBox and ShowMsg with  QuestionDlg.


Edit: Since *Edson mentioned MsgErr, IMHO using whatever print only dialogue for displaying errors is a mistake. Text printed on an error dialogue shall be copyable, so users could easily post/write somewhere "I got the following error message..... What to do?"
« Last Edit: October 07, 2014, 07:54:56 am by paskal »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

nocuttree

  • New Member
  • *
  • Posts: 36
Re: application.messagebox
« Reply #6 on: October 07, 2014, 03:08:10 pm »
As I always do- I recommend using QuestionDlg than anything else. Because one day you decide to make a multi-language app and you start replacing all Application.MessageBox and ShowMsg with  QuestionDlg.


Edit: Since *Edson mentioned MsgErr, IMHO using whatever print only dialogue for displaying errors is a mistake. Text printed on an error dialogue shall be copyable, so users could easily post/write somewhere "I got the following error message..... What to do?"
Also, you can use my library: https://github.com/t-edson/MisUtils
and use:
* MsgBox() -> for showing messages
* MsgExc() -> for showing messages with the Exclamation Icon
* MsgErr() -> for showing messages with the Error Icon

Moreover, these procedures admit translation for other languages.
Thanks you!
Sorry my English, Windows xp, Lazarus 1.2.2!

 

TinyPortal © 2005-2018