Solved

incorporating the path of the file that will be displayed in the listbox

Posted on 2003-10-25
2
171 Views
Last Modified: 2011-09-20
Hi, how can we incorporate the path of a file that will be added to the listbox
without having it to be displayed in the listbox.. example>
what i want is that in the list box it will display

z21001.zip but it carries the path of this file silently..

and not this one

c:\progra~1\z21001.zip


in the list its just z21001.zip.. hope you understand.. thanks





0
Comment
Question by:orafans
2 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9619219
Either:
1. Have a seperate string list which stores the full path
2. Use OwnerDraw so that you draw the item yourself - internally it would be stored with the path but when you display it, just draw ExtractFileName(path).

Example for 2:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect:TRect;State: TOwnerDrawState);
begin
      with (Control as TListBox).Canvas do  { draw on control canvas, not on the form }
      begin
            FillRect(Rect);       { clear the rectangle }
            TextOut(Rect.Left, Rect.Top, ExtractFileName((Control as TListBox).Items[Index]))
      end;
end;

Geoff M.
0
 
LVL 4

Accepted Solution

by:
nestorua earned 125 total points
ID: 9619571
HI,
You can do it the following way (very useful indeed):

TYPE
 TPathStr=class
   FullPath: string;
    constructor Create(AFullPath: string);
  end;

{ TMyStr }
constructor TPathStr.Create(AFullPath: string);
begin
 Inherited Create;
 FullPath:=AFullPath;
end;

procedure TForm1.AddItemToListBox(FileName: string);
begin
 with ListBox1.Items do
    AddObject(ExtractFileName(FileName), TPathStr.Create(FileName));
end;
Sincerely,
Nestorua.
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 177
Delphi XE10 Round Image 2 183
FMX and jaudiotracker playing memory stream 29 97
Tvertscrollbox like a whatsapp layout delete messages 1 38
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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