Solved

Shortened pathname with \...\

Posted on 1998-09-03
6
490 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 100 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can't find the executable in Simulator 1 89
Find and Replace Stream with 0s 8 61
JAudiorecorder record freezing the app 29 67
Graphics32 under Delphi 10.1 Berlin 2 60
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now