rclay
asked on
Shortened pathname with \...\
How do I shorten pathnames to fit a certain length space using an ellipsis (...) between backslashes?
If you want to do it the "Windows Way", let me know and I'll show you how to do it..
ASKER
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.
Blackman: Yes, I would like to know how to do it the windows way.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the input Viktornet, JimBob, and BlackMan!
var
Path : string;
procedure TForm1.Button1Click(Sender
begin
if Length(path) > 10 then
Path := Copy(path, 1, 10) + '\...\';
Caption := Path;
end;
procedure TForm1.Button2Click(Sender
begin
Path := 'C:\windows\desktop\Viktor
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\...
Regards,
Viktor Ivanov