I have it working better now.  
I was having a crash with Code 216 
Appearantly 
   SaveAsFileName.lpstrFile:= Pchar(DefaulSaveAsFileName);
Just doesn't work the way I want it to.  If I try to do the conversion to
Pchar that way, I get an error 216 on:
  SaveAsResult:=GetSaveFileNameA(@SaveAsFileName);
 
I ended up making a buffer
SaveAsFileNameBuffer: array[0..Max_Path+1] of char;
 
Then putting my default file name in the buffer with:
SaveAsFileNameBuffer:=Pchar(DefaulSaveAsFileName);
 
Then assigning the buffer with:
SaveAsFileName.lpstrFile:=SaveAsFileNameBuffer;
 
So even though it looks like that would be the same thing as:
SaveAsFileName.lpstrFile:= Pchar(DefaulSaveAsFileName);    It is not.. and
even though I had  SaveAsFileName.nMaxFile:=Max_Path+1;
SaveAsFileName.lpstrFile:= Pchar(DefaulSaveAsFileName);   still fails with a
216
 
Here is my complete test program, I'm not positive it's completely correct,
but it seems to work better:
 
Program TestGetSaveFileNameA;
Uses windows, commdlg;
 
Var
    SaveAsFileName   : TOpenFileNameA;
    SaveAsResult     : Boolean;
    DefaulSaveAsFileName,OutpuSaveAsFileName : Ansistring;
    SaveAsFileNameBuffer: array[0..Max_Path+1] of char;
    MyFile : Text;
 
Begin
   DefaulSaveAsFileName := 'X:\Something with a really really really long
long long long file name to see if there is still a bug with really long
filenames.tap';
   fillchar(SaveAsFileName, sizeof(SaveAsFileName), 0);
   SaveAsFileName.lStructSize:=sizeof(SaveAsFileName);
   SaveAsFileName.hwndOwner:=0;
   SaveAsFileName.nMaxFile:=Max_Path+1;
//   SaveAsFileName.lpstrFile:=Pchar(DefaulSaveAsFileName);    // This
causes an Error 216
   SaveAsFileNameBuffer:=Pchar(DefaulSaveAsFileName);
   SaveAsFileName.lpstrFile:=SaveAsFileNameBuffer;
   SaveAsFileName.lpstrFilter:='TAP Files (*.tap)'+#0+'*.tap'+#0;
   SaveAsFileName.Flags := OFN_EXPLORER;
   SaveAsFileName.lpstrDefExt:='tap';
   SaveAsFileName.lpstrTitle:='Save File As:';
   Writeln(SaveAsFileName.lpstrFile,' ',SaveAsFileName.nMaxFile);
   SaveAsResult:=GetSaveFileNameA(@SaveAsFileName);
   Writeln(SaveAsResult,'  File Name Selected: ',SaveAsFileName.lpstrFile);
   If SaveAsResult then
      Begin
         OutpuSaveAsFileName:=strpas(SaveAsFileName.lpstrFile);
         Writeln('File Name AnsiString: '+OutpuSaveAsFileName);
         Assign(MyFile,OutpuSaveAsFileName);
         ReWrite(MyFile);
         Writeln(MyFile,'Test');
         Writeln(MyFile,OutpuSaveAsFileName);
         Close(MyFile);
      End;
End.
 
James
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to