Solved

Fit this path into this edit please!

Posted on 2006-07-10
14
424 Views
Last Modified: 2010-04-05
Hi my dear friends!

After numerous attempts to fit this path into my edit, I turn to you! This is my code....

//Code

var
  lpbi: TBrowseInfo;
  pidlStart: PItemIDList;
  Malloc: IMalloc;
  sSelected: string;
  pidlSelected: PItemIDList;
  edt: TAHMStoreEdit;
begin
  SHGetSpecialFolderLocation(Handle, $00, pidlStart);
  SHGetMalloc(Malloc);
  with lpbi do
  begin
    hwndOwner := Handle;
    pidlRoot := pidlStart;
    GetMem(pszDisplayName, MAX_PATH);
    lpszTitle := PChar('Selecteer folder');
    ulFlags := $00000001;
    lpfn := nil;
  end;
  pidlSelected := SHBrowseForFolder(lpbi);
  if pidlSelected <> nil then
  begin
    if SHGetPathFromIDList(pidlSelected, lpbi.pszDisplayName) then
    sSelected := StrPas(lpbi.pszDisplayName);
     if (Sender is TspeedButton) then
    begin
      Edt := FindComponent('edt' + Copy((Sender as TspeedButton).Name, 4, 255)) as
        TAHMSTOREEdit;
        Edt.Text := sSelected;

<<<<< something here I guess? >>>>>

    Malloc.Free(pidlSelected);
  end;
  FreeMem(lpbi.pszDisplayName);
  Malloc.Free(pidlStart);
end;

//Code

When the string is too large for my edit it should be truncated into something like:

 C:\...My Hidden Folder\Jenna Jameson...:) instead of
C:\Nothing Special Here\Just Normal Folders\Really Nothing Abnormal Here\Believe Me Please\My Hidden Folder\Jenna Jameson :)

Regards Paul

Ps working samples do the trick...my numerous attempts resulted in nearly eating my LCD screen :)
0
Comment
Question by:PeterdeB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
14 Comments
 

Author Comment

by:PeterdeB
ID: 17073203
Ok, lets try this again.  I just re-read your original request and realized I was only giving you the filename and not the last directory as well.  The following should work.

procedure Shorten(var fPath : string);
var
 ii : integer;
 count : integer;
 startPos,stop : integer;
 prevStop : integer;
begin
 count := 0;
 startPos := 0;
 stop := 0;
 prevStop := 0;
 for ii := 1 to length(fPath) do begin
   // look for all the separators
   if fPath[ii] = '\'  then begin
     count := count + 1;  // count them
     if count = 2 then startPos := ii + 1  // 2nd is start
     else begin
       prevStop := stop;
       stop := ii;
     end;
   end;
 end;
 if (count > 3) and (prevStop > (startPos + 2)) then begin
   // we had at least 4 separators and can shorten
   fPath[startPos] := '.';
   fPath[startPos+1] := '.';
   fPath[startPos+2] := '.';
   startPos := startPos + 3;  // elipses
   for ii := prevStop to length(fPath) do begin
     // copy the last separator and the filename
     fPath[startPos] := fPath[ii];
     startPos := startPos + 1;
   end;
   setLength(fPath,startPos - 1);  // shorten the string
 end;
end;

From jbshumate!

Just tried it and it works!

Regards Paul :)
0
 
LVL 28

Expert Comment

by:2266180
ID: 17074953
I am officially confused
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 125 total points
ID: 17075016

uses

  FileCtrl

 
...


var
  a_Dir: string;
begin
  Canvas.Font := Edit1.Font;
  a_edit1.text:= MinimizeName('C:\my very very longdirectory\myshortdir\', Canvas, Edit1.width);
end;
0
Technology Partners: 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!

 

Author Comment

by:PeterdeB
ID: 17075849
Hi folks!

Rightly after I posted my question I went through EE's database and found a similar post to mine and a reply from jbshumate. I will now try House of Dexters reply!

Regards Paul :)
0
 
LVL 28

Expert Comment

by:2266180
ID: 17075869
in that case, next time, it is better to post the link ;) (will better help future readers)
0
 

Author Comment

by:PeterdeB
ID: 17075913
I think this will help future readers as well. They will find my post and wil find the answer as well.

Regards Paul
0
 
LVL 28

Expert Comment

by:2266180
ID: 17075977
true, but it is better to include the link so that they can see the whole conversation. it sometimes happens that someone doesn't look for this particular solution, but has another related problem, and it happens that that exact problem is being discussed in similar questions ;)

it's just the best thing to do :) but of course it's your decision, I only gave you an advice ;)
0
 

Author Comment

by:PeterdeB
ID: 17076160
Ok thanks for your advice then Ciuly, I suppose I could still post the link right?

Regards Paul
0
 
LVL 28

Expert Comment

by:2266180
ID: 17076200
well sure :) there are no rules for this afaik. that is why I said it was an advice (suggestion) :)
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17085699
FWIW the term for this shortening (where you put 3 dots in the middle) is called "ellipsis"

eg. here is how you would do it on a canvas

 procedure TForm1.PaintBox1Paint(Sender: TObject);
  var
    DTParams: DrawTextParams;
    Rect : TRect;
  begin
    with DTParams do begin
      cbSize := SizeOf(DrawTextParams);
      iTabLength := 6;
      iLeftMargin := 2;
      iRightMargin := 2;
    end;
    Rect := Paintbox1.ClientRect;
    Paintbox1.Canvas.Rectangle(Rect);
    DrawTextEx(Paintbox1.Canvas.Handle, PChar(Paintbox1.Hint), -1,
      Rect, DT_CENTER + DT_VCENTER + DT_SINGLELINE + DT_END_ELLIPSIS,
      @DTParams);
  end;
0
 

Author Comment

by:PeterdeB
ID: 17117534
Hi my dear friends!

I just tried House_of_Dexters reply and this works perfect. Since I already had the FileCtrl unit in my uses clause, his answer beats the shorten procedure from jbshumate.

TheRealLoki > thanks for your reply anyway! I did not further test it since the reply from House_of_Dexter seems the easiest way to do this.

Regards Paul :)
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17118397
that's ok, i just added it in case others were to search for this solution
0
 

Author Comment

by:PeterdeB
ID: 17122618
Ok thanks for the feedback.

Regards Paul
0

Featured Post

Industry Leaders: 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!

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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