Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shortened pathname with \...\

Posted on 1998-09-03
6
Medium Priority
?
516 Views
Last Modified: 2010-08-05
How do I shorten pathnames to fit a certain length space using an ellipsis (...) between backslashes?
0
Comment
Question by:rclay
6 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1338552
How about something similar to this.,.....

var
  Path : string;
procedure TForm1.Button1Click(Sender: TObject);
begin
  if Length(path) > 10 then
    Path := Copy(path, 1, 10) + '\...\';
  Caption := Path;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  Path := 'C:\windows\desktop\Viktor\Delphi';
  Caption := Path;
end;

Hope it helps! There are other ways to do that with the API, but it's not exactly what you are looking for     it does like this  C:\windows\desktop\vik...  and not C:\windows\desktop\vik\...\...\and so on.....

Regards,
Viktor Ivanov
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1338553
If you want to do it the "Windows Way", let me know and I'll show you how to do it..
0
 

Author Comment

by:rclay
ID: 1338554
Viktornet: What I'm looking for is a function or procedure that shortens the path by omitting its middle part, substituting an ellipsis. But it would break the pathname at a '\', not at some arbitrary point such as at the 10th character. Also the total length of the resulting pathname should be adjustable at design- or run-time by the programmer.

Blackman: Yes, I would like to know how to do it the windows way.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1338555
Hi

The DrawTextEx API function will fill in the ellipsis for you.  You give the function a string (PChar), a rectangle and a canvas, and if the text doesn't fit into the rectangle then it uses ellipsis.

E.g.
DrawTextEx(Canvas.Handle, PChar(SomeStr), Length(SomeStr), SomeRect, DT_PATH_ELLIPSIS or DT_MODIFYSTRING, nil);

Unfortunately you don't get the result string (with ellipsis) back.

JB
0
 
LVL 7

Accepted Solution

by:
BlackMan earned 400 total points
ID: 1338556
Here's an example (taken from a "live" application). It takes the value of AString and shorten it so that it fits in Label1.

Var
  AString: String;
  r: TRect;
begin
  AString := '\\MyServer\MyShare\ThisDirectory\ThatDirectory\MyFile';
  r.Left := 0;
  r.Right := Label1.Width;
  r.Top := 0;
  r.Bottom := Label1.Height;
  Windows.DrawText(Label1.Canvas.Handle, @AString[1], Length(AString), r, DT_Left or DT_PATH_ELLIPSIS or DT_MODIFYSTRING or DT_CALCRECT );
  Label1.caption := AString;
End;
0
 

Author Comment

by:rclay
ID: 1338557
Thanks for the input Viktornet, JimBob, and BlackMan!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question