The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
ComboBoxes and Filenames
Discuss ComboBoxes and Filenames in the Delphi Programming forum on Dev Shed. ComboBoxes and Filenames Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 14th, 2004, 02:18 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
ComboBoxes and Filenames
Hey all
im kinda new to delphi 7, well delphi in general
my problem is i need to read a filename into a combobox, the file is always a text file and should be in the same directory always. if anyone knows how to do this it would be greatly appreciated. do i need to go from a string variable containing the file location or what im so confused with this. Its prolly very easy
any ideas are appreciated
thank Brend0
|

April 16th, 2004, 07:15 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
I'm not certain what you mean exactly, but doesn't this work?
Code:
Combobox1.Text := 'Somefilename';
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|

April 17th, 2004, 05:26 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Ok sorry not clear enough. I need to read several "names" of textfiles, but what is in the folder where they are located will change so i cant just write textfile1 and textfile2 i need it so if a person creates textfile3 it will be in the combobox list as well.
something like
for allfiles in C:MyProgram/TextFiles/
put all file 'names' into combobox1.list
thanks alot
Last edited by Brend0 : April 17th, 2004 at 05:34 AM.
|

April 17th, 2004, 10:23 AM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
You want to search a directory for file names?
The code looks similar to this:
Code:
var
mySearchRec: TSearchRec;
begin
myComboBox.Items.Clear;
FindFirst('C:\folder\*.*', mySearchRec);
repeat
if (mySearchRec.Attributes AND faDirectory)=0 then begin { entry is not a directory }
myComboBox.Items.Add(mySearchRec.FileName);
end;
until FindNext(mySearchRec)=0
end;
I don't have Delphi at home (yet), so this is straight from my head. I probably messed up the parameter order as well as the part with the return code of "FindNext()". And I am not sure if it is "myCheckBox.Items" either. So please make sure you check the help file before telling us that it doesn't work.
Also, the code is faulty in that it doesn't check the success of the FindFirst call and also would not sort out volume labels on floppies.
But it's weekend now, so this is not my task to solve
hth,
M.
|

April 19th, 2004, 02:11 AM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Thanks
thats exactly what i needed to do
its working perfect now
thanks M. Hirsch
from Brend0 
|

August 23rd, 2012, 09:46 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 29
Time spent in forums: 4 h 36 m 52 sec
Reputation Power: 0
|
|
I tried the code. I had error:
incompatible types: integer and tsearchrec...
help please......
Quote: | Originally Posted by M.Hirsch You want to search a directory for file names?
The code looks similar to this:
Code:
var
mySearchRec: TSearchRec;
begin
myComboBox.Items.Clear;
FindFirst('C:\folder\*.*', mySearchRec);
repeat
if (mySearchRec.Attributes AND faDirectory)=0 then begin { entry is not a directory }
myComboBox.Items.Add(mySearchRec.FileName);
end;
until FindNext(mySearchRec)=0
end;
I don't have Delphi at home (yet), so this is straight from my head. I probably messed up the parameter order as well as the part with the return code of "FindNext()". And I am not sure if it is "myCheckBox.Items" either. So please make sure you check the help file before telling us that it doesn't work.
Also, the code is faulty in that it doesn't check the success of the FindFirst call and also would not sort out volume labels on floppies.
But it's weekend now, so this is not my task to solve
hth,
M. |
|

August 23rd, 2012, 10:01 AM
|
|
Contributing User
|
|
Join Date: Jun 2008
Posts: 254
 
Time spent in forums: 2 Days 23 h 55 m 14 sec
Reputation Power: 5
|
|
try this:
Code:
var
SearchRec: TSearchRec;
begin
if (FindFirst('C:\YourPath\*.txt', faAnyFile-faDirectory, SearchRec) = 0) then
try
repeat
MyComboBox.Items.Add(mySearchRec.FileName);
until (FindNext(SearchRec <> 0));
finally
FindClose(SearchRec);//without close you will have memory leak.
end;
end;
|

August 23rd, 2012, 05:28 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 29
Time spent in forums: 4 h 36 m 52 sec
Reputation Power: 0
|
|
Modifying a couple lines become:
procedure TForm2.FormCreate(Sender: TObject);
begin
if (findfirst('d:\mevcut\*.txt',faAnyfile-faDirectory,SearchRec)=0) then
try
repeat
combobox1.Items.Add(searchrec.Name);
until(findnext(searchrec)<>0);
finally
findclose(searchrec);
end;
end;
which runs perfectly...
thanks.
Quote: | Originally Posted by majlumbo try this:
Code:
var
SearchRec: TSearchRec;
begin
if (FindFirst('C:\YourPath\*.txt', faAnyFile-faDirectory, SearchRec) = 0) then
try
repeat
MyComboBox.Items.Add(mySearchRec.FileName);
until (FindNext(SearchRec <> 0));
finally
FindClose(SearchRec);//without close you will have memory leak.
end;
end;
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|