2

I'm showing where a file has been saved by using 'Showmessage' (in Win 7). When the file path is long it gets truncated and elipsis get inserted. eg the path

C:\Users\Admin\Documents\SubFolderOne\AnotherSubFolder\MyFile.csv

gets displayed as

C:\Users\Admin\Documents\SubFolderOne\Ano...\MyFile.csv

Is there a way to make the message box wider and show all of the filename and path?

I have read this http://zarko-gajic.iz.hr/displaying-long-non-breakable-text-file-path-in-messagedlg-truncationellipsis-issues/ which explains some of the reasoning and gives a rather unsatisfactory method for a TTaskDialog and I also I realise I could make my own form to act in the same way as Showmessage but I am wondering if there is a simpler solution using just Showmessage.

Ken White
  • 123,280
  • 14
  • 225
  • 444
user3209752
  • 619
  • 2
  • 17
  • 29
  • Split your string to several lines, like `Copy(s, 1, 32) + ' ... '#13 + Copy(s, 33, Length(s))` – Abelisto Oct 23 '15 at 12:54
  • Possible I guess. To make it look at all neat though I'd have to find the last backslash in the path that would fit across one line in the message window and split it there, but it still wouldn't read like a single filename and path – user3209752 Oct 23 '15 at 15:31
  • 1
    Design your own form instead of using `ShowMessage`; that form can do whatever you want. You can create your own function that accepts a string, creates the form, and displays the string in whatever manner you'd like. – Ken White Oct 24 '15 at 01:24
  • 1
    See this great answer on TTaskDialog here: https://stackoverflow.com/questions/4979556/how-to-use-the-ttaskdialog – Gabriel Dec 11 '17 at 12:58

2 Answers2

2

Is a simpler solution using just ShowMessage?

No there is not.

I can think of three obvious approaches, although doubtless there are more.

Create your own dialog

There's nothing particularly magical about a dialog. You can perfectly well create them yourself, and so have complete control over their appearance. The downside of course is that it can be hard to match the native platform appearance. Especially when you consider all the different Windows versions that you are typically expected to support.

Use CreateMessageDialog and customise this Delphi form

You can call the RTL function CreateMessageDialog to obtain a Delphi form that can be used to display your message dialog. You then have the opportunity to customize this dialog in any way you please.

Use the task dialog API

The task dialog API, introduced in Vista, affords control of the dialog width. Call TaskDialogIndirect, and specify a non-zero value for cxWidth.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thank you. As I mentioned in my post I did conder those options and do already I make my own custom dialogs quite frequently. My question was really to do with Showmessage specifically and whether there was some property or method I could use to change its appearance. – user3209752 Oct 23 '15 at 15:28
  • That's simple. The answer is no. Such an answer tends not to be very well received, so I expanded. – David Heffernan Oct 23 '15 at 15:32
  • So, did we answer your question then? – David Heffernan Oct 24 '15 at 12:53
  • In the sense that I asked 'Can I' and you answered 'No' then yes you have answered it, thank you ! I'll just go with making my own form as usual. Sorry for the delay in accepting but I don't find navigating the site all that easy and sometimes lose track of my own posts so I can't see if anyone has answered it. – user3209752 Nov 09 '15 at 08:56
  • The most simple and quick solution is Petrus' - see below. – Semanino Oct 15 '19 at 06:16
  • @semanino Quick yes, but with side effects that are likely undesirable – David Heffernan Oct 15 '19 at 06:40
2

Before ShowMessage put:

UseLatestCommonDialogs:= false;

I use Delphi 10.2 and it works.

Petrus
  • 59
  • 5
  • One might want to put that line into the `.dpr` file; since `UseLatestCommonDialogs` is a global variable in `Vcl.Dialogs.pas`, it affects the whole application anyway once it is changed. This is IMHO for sure the absolute quickest way to get rid of that nasty abbreviation "feature". – Semanino Oct 15 '19 at 06:20