Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 14th, 2004, 02:18 AM
Brend0 Brend0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 Brend0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 16th, 2004, 07:15 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,387 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 21 h 39 m 3 sec
Reputation Power: 4080
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

Reply With Quote
  #3  
Old April 17th, 2004, 05:26 AM
Brend0 Brend0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 Brend0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old April 17th, 2004, 10:23 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
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.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #5  
Old April 19th, 2004, 02:11 AM
Brend0 Brend0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 Brend0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Thanks

thats exactly what i needed to do
its working perfect now

thanks M. Hirsch

from Brend0

Reply With Quote
  #6  
Old August 23rd, 2012, 09:46 AM
turkalpk turkalpk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 29 turkalpk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #7  
Old August 23rd, 2012, 10:01 AM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 254 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
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;

Reply With Quote
  #8  
Old August 23rd, 2012, 05:28 PM
turkalpk turkalpk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 29 turkalpk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > ComboBoxes and Filenames

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap