Peter Kiers
asked on
Check ik file exist
Dear experts,
I have this to load and save the 3 listviews to file.
procedure TMainForm.FormClose(Sender : TObject; var Action: TCloseAction);
begin
SaveListViewToFile(lstvGlu cose, 'Glucose.sav');
SaveListViewToFile(lstvBol us, 'Bolus.sav');
SaveListViewToFile(lstvFoo dDB, 'FoodDB.sav');
end;
(*------------------------ ---------- ---------- -------*)
procedure TMainForm.FormCreate(Sende r: TObject);
begin
LoadListViewToFile(lstvGlu cose, 'Glucose.sav');
LoadListViewToFile(lstvBol us, 'Bolus.sav');
LoadListViewToFile(lstvFoo dDB, 'FoodDB.sav');
end;
But when I start my application the first time the files doesn't exits yet.
so, I get 3 times a error message. How can I prevent this.
That the programm first look if the fileexist otherwist create it.
P
I have this to load and save the 3 listviews to file.
procedure TMainForm.FormClose(Sender
begin
SaveListViewToFile(lstvGlu
SaveListViewToFile(lstvBol
SaveListViewToFile(lstvFoo
end;
(*------------------------
procedure TMainForm.FormCreate(Sende
begin
LoadListViewToFile(lstvGlu
LoadListViewToFile(lstvBol
LoadListViewToFile(lstvFoo
end;
But when I start my application the first time the files doesn't exits yet.
so, I get 3 times a error message. How can I prevent this.
That the programm first look if the fileexist otherwist create it.
P
ASKER
It has to be like this:
If file does not exits in the application-folder
then create one.
P.
If file does not exits in the application-folder
then create one.
P.
If I understand you correctly, this will do it :
procedure TMainForm.FormCreate(Sende r: TObject);
begin
if FileExists('Glucose.sav') then LoadListViewToFile(lstvGlu cose, 'Glucose.sav');
if FileExists('Bolus.sav') then LoadListViewToFile((lstvBo lus, 'Bolus.sav');
if FileExists('FoodDB.sav') then LoadListViewToFile(lstvFoo dDB, 'FoodDB.sav');
end;
procedure TMainForm.FormClose(Sender : TObject; var Action: TCloseAction);
begin
if FileExists('Glucose.sav') then DeleteFile('Glucose.sav');
SaveListViewToFile(lstvGlu cose, 'Glucose.sav');
if FileExists('Bolus.sav') then DeleteFile('Bolus.sav');
SaveListViewToFile(lstvBol us, 'Bolus.sav');
if FileExists('FoodDB.sav') then DeleteFile('FoodDB.sav');
SaveListViewToFile(lstvFoo dDB, 'FoodDB.sav');
procedure TMainForm.FormCreate(Sende
begin
if FileExists('Glucose.sav') then LoadListViewToFile(lstvGlu
if FileExists('Bolus.sav') then LoadListViewToFile((lstvBo
if FileExists('FoodDB.sav') then LoadListViewToFile(lstvFoo
end;
procedure TMainForm.FormClose(Sender
begin
if FileExists('Glucose.sav') then DeleteFile('Glucose.sav');
SaveListViewToFile(lstvGlu
if FileExists('Bolus.sav') then DeleteFile('Bolus.sav');
SaveListViewToFile(lstvBol
if FileExists('FoodDB.sav') then DeleteFile('FoodDB.sav');
SaveListViewToFile(lstvFoo
ASKER
I found out myself:
procedure TMainForm.FormCreate(Sende r: TObject);
begin
PgCtrlMain.ActivePage := tbshGlucose;
if FileExists(ExtractFilePath (Applicati on.ExeName ) + 'Glucose.sav') then
LoadListViewToFile(lstvGlu cose, 'Glucose.sav');
if FileExists(ExtractFilePath (Applicati on.ExeName ) + 'Bolus.sav') then
LoadListViewToFile(lstvBol us, 'Bolus.sav');
if FileExists(ExtractFilePath (Applicati on.ExeName ) + 'FoodDB.sav') then
LoadListViewToFile(lstvFoo dDB, 'FoodDB.sav');
end;
procedure TMainForm.FormCreate(Sende
begin
PgCtrlMain.ActivePage := tbshGlucose;
if FileExists(ExtractFilePath
LoadListViewToFile(lstvGlu
if FileExists(ExtractFilePath
LoadListViewToFile(lstvBol
if FileExists(ExtractFilePath
LoadListViewToFile(lstvFoo
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if FileExists(File_Name) then DeleteFile(File_Name);