Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2011, 04:16 AM
Moondancer Moondancer is offline
Junior Member
 
Join Date: Apr 2011
Posts: 22
Default stringgrid - load to and from

I am trying to load my stringgrid from a text file.However,I must check if file exists first. If it does not, then create it (the file) and then try once more to load the stringgrid from that file.
Just want to make sure my stringgrid will have a file to load from.
And once again,how do I save stringgrid contents to that file (checking if its there first) ?
Possibly avoiding using TStringlist ...

p.s
the file (*.txt) is in my app exe folder
Reply With Quote
  #2  
Old 07-28-2011, 08:34 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

if a file exists you can use the function FileExists()

StringGrid doesn't save/load to a file, you'll have to write does routines yourself... Possibly a simple csv structure would do fine for you...
Reply With Quote
  #3  
Old 07-28-2011, 01:35 PM
Moondancer Moondancer is offline
Junior Member
 
Join Date: Apr 2011
Posts: 22
Default

I am sure I am messing something up but cant figure out what ...
I was doing this:

procedure TForm1.FormCreate(Sender: TObject);
Var
I,j:Integer;
ApplicationPath: string;
List:TStrings;
begin
ApplicationPath :=ExtractFileDir(Application.ExeName);
if not FileExists (ApplicationPath+'\box.txt') then begin
List:=TStringList.Create;
try
for i:=0 to advStringGrid1.ColCount-1 do
List.AddStrings(advStringGrid1.Cols [i]);

for i:=0 to advStringGrid1.rowCount-1 do
List.AddStrings(advStringGrid1.rows [j]);

List.SaveToFile(ApplicationPath+'\box.txt');
finally
List.free;
end ;
end
else abort;
end;

I was saving contents to file but I think this is not a good approach.
Am I right ?

Or would it be better to just create the file...
Reply With Quote
  #4  
Old 07-28-2011, 01:46 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

This will only save if the file does not exist, so every attempt after the first will not save your changes...
Furthermore, the location (applicationpath) is nowadays only reachable by running as administrator... Perhaps you'll get some error you're not aware of, message the error after the savetofile -> ShowMessage(SysErrorMessage(GetLastError()));

But the weardest part, in your formcreate you save the content of a visual control to a txt file... I think this will not save more then just a little header information (if it's correct)
Reply With Quote
  #5  
Old 07-29-2011, 12:16 AM
Moondancer Moondancer is offline
Junior Member
 
Join Date: Apr 2011
Posts: 22
Default

You are right ... it might just be better to just create files and leave loading/saving to some other control...
Reply With Quote
  #6  
Old 08-08-2011, 07:39 AM
lucyjoin89757 lucyjoin89757 is offline
Junior Member
 
Join Date: Aug 2011
Posts: 4
Default

Quote:
Originally Posted by Moondancer View Post
You are right ... it might just be better to just create files and leave loading/saving to some other control...

Reply With Quote
  #7  
Old 08-17-2011, 07:36 PM
Donovan Donovan is offline
Senior Member
 
Join Date: Jan 2011
Posts: 150
Send a message via Skype™ to Donovan
Default

The jedi component set have a CSVdataset component which sounds like it would be perfect here and will require much less effort
Reply With Quote
Reply

Tags
delphi, delphi 2010, delphi7

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:50 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.