[Lazarus] Test de l'existence des fichiers
Bonjour,
Voila, j'ai un petit programme dans lequel je teste l'existence d'un fichier grace a la fontion Not_Exist :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
function not_exist(var Fich : File) : boolean;
begin
{$I-}
Reset(fich);
{$I+}
if IOResult = 0 then
begin
not_exist := False;
close(Fich);
end
else not_exist := True;
end;
procedure TForm_general.FormCreate(Sender: TObject);
Var NomFichier : file ;
begin
Assignfile(NomFichier, 'Categ.Dbf');
If not_exist(NomFichier) then
begin
Dbf_Cat.TableLevel := 4;
Dbf_Cat.TableName := 'Categ.dbf';
With Dbf_Cat.FieldDefs do
begin
Add('CAT', ftString, 2, True);
Add('LIBELLE', ftString, 35, True);
Add('COT_OBLIG', ftboolean,0,true);
Add('POSSIB_APP', ftboolean,0,true);
Add('COTISATION', ftfloat,0,true);
End;
Dbf_Cat.CreateTable;
end;
end; |
Je teste donc dès la création du Tform l'existence des fichiers à utiliser.
Si mon fichier existe, je l'ouvre sinon, je le crée ce qui exclut normalement tout risque d'erreur.
Tout ça fonctionne à merveille quand je compile et exécute sous W98. Et quand j'exécute sous XP, ça plante ! Il me dit que le fichier n'existe pas (alors qu'il existe bien !). Et même en admettant qu'il n'existe pas, il devrait me le créer :roll: ... Alors pourquoi ? :mur:
A+