Solved

Fit this path into this edit please!

Posted on 2006-07-10
14
414 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
  • 7
  • 4
  • 2
  • +1
14 Comments
 

Author Comment

by:PeterdeB
Comment Utility
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:ciuly
Comment Utility
I am officially confused
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 125 total points
Comment Utility

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
 

Author Comment

by:PeterdeB
Comment Utility
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:ciuly
Comment Utility
in that case, next time, it is better to post the link ;) (will better help future readers)
0
 

Author Comment

by:PeterdeB
Comment Utility
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:ciuly
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

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

Regards Paul
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
well sure :) there are no rules for this afaik. that is why I said it was an advice (suggestion) :)
0
 

Author Comment

by:PeterdeB
Comment Utility
0
 
LVL 17

Expert Comment

by:TheRealLoki
Comment Utility
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
Comment Utility
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
Comment Utility
that's ok, i just added it in case others were to search for this solution
0
 

Author Comment

by:PeterdeB
Comment Utility
Ok thanks for the feedback.

Regards Paul
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

16 Experts available now in Live!

Get 1:1 Help Now