Thanks for the gersavefilenamea idea, I have used windows API function calls 
before in my Windows Console programs, so I thought I would try to get 
getsavefilenamea or ifilesavedialog to work in my console program.  So I 
thought I would start small and get message boxes to work on my console 
program, this was actually pretty easy, I just added the windows unit to my 
program and then changed my writeln's to 
windows.messagebox(0,pchar(TapFileName+' Not Found'),pchar('Error'),MB_OK);

And poof I get a message box when I encounter the error, and the program waits 
until I hit OK to continue.  Neat!  

 

So it's looking promising, that perhaps I can just keep it a console program 
that launches the save-as dialog somehow when needed.    This idea appeals to 
me for several reasons, first, I need to write the status of things somewhere,  
it's easy to just have a writeln in a console application, but in a windows 
application, I have no idea how I would make some kind of text box to display 
this information.   Also, I want this program to start executing immediately, 
and if no user intervention is needed, I want it to launch, perform all tasks, 
and exit.  I just don't have anything to put on a form because the intent is 
that the user would only interact with this program if it encountered an error, 
or if the user needed to specify the output file name.

 

So my question is, how can I use Ifilesavedialog with just FreePascal in a 
console application?  I tried just accessing it the same as I did messagebox, 
but I just get an error stating the function is not found.   It seems like I 
ran across this before, I wanted to use a Windows API function that was not 
included in the windows unit and I was somehow able to add access to it on my 
own,  but I just can't recall now what function that was, or what program I was 
working on that needed it, or how it was accomplished.   Perhaps it is in the 
windows unit, or another unit, but I'm just not calling it correctly.   Current 
version of my program that uses message boxes for errors is below.

 

James

 

Program JobsList;

Uses CRT,Classes,Sysutils,windows;

Var

   TapFileRemainder,TapFileHeader,TapFileJobsList : tstrings;

   TapFileName,TapFileData,OutputTapFileName      : AnsiString;

   TapFile                                        : Text;

   TapFileHeaderActive                            : Boolean;

   StringCount                                    : LongInt;

Begin

   If ParamStr(1)<>'' Then

      Begin

         TapFileName:=ParamStr(1);

         If FileExists(TapFileName) Then

            Begin

               TapFileHeaderActive:=True;

               Assign(TapFile,TapFileName);

               Reset(TapFile);

               TapfileHeader:=TStringlist.Create;

               TapfileJobsList:=TStringlist.Create;

               TapfileRemainder:=TStringlist.Create;

               While not(EOF(TapFile)) do

                  Begin

                     Readln(Tapfile,TapFileData);

                     If TapfileHeaderActive then

                        Begin

                           If TapFileData='Call [Subroutines]' Then

                              Begin

                                 Writeln('Subroutine Section Found');

                                 TapFileHeaderActive:=False

                              End

                           Else

                           If Copy(TapFileData,1,15)='Tap File Name =' Then

                              Begin

                                 
OutputTapFileName:=Copy(TapFileData,16,Length(TapFileData)-15);

                                 Writeln('Saving to: '+OutputTapFileName);

                              End

                           Else

                              TapfileHeader.Add(TapFileData)

                        End

                     Else

                        Begin

                           If Copy(TapFileData,1,6)='[Job #' Then

                              Begin

                                 Writeln(TapFileData);

                                 TapFileJobsList.Add('Call '+TapFileData);

                              End;

                           TapfileRemainder.Add(TapFileData)

                        End;

                  End;

               Close(TapFile);

               If OutputTapFileName='' Then

                  Begin

                     {Do something to get filename from windows Save-As dialog}

                     {OutputTapFileName:= 
Whatever-was-received-by-Windows-Save-As-dialog;}

                  End;

               If OutputTapFileName<>'' Then

                  Begin

                     Writeln('Writing 
',TapFileHeader.count+TapFileJobsList.count+TapFileRemainder.count,' Lines to: 
'+OutputTapFileName);

                     Assign(TapFile,OutputTapFileName);

                     ReWrite(TapFile);

                     If TapFileHeader.count > 1 then

                     For StringCount:=0 to TapFileHeader.count-1 do

                        Writeln(TapFile,TapFileHeader[StringCount]);

                     If TapFileJobsList.count > 1 then

                     For StringCount:=0 to TapFileJobsList.count-1 do

                        Writeln(TapFile,TapFileJobsList[StringCount]);

                     If TapFileRemainder.count > 1 then

                     For StringCount:=0 to TapFileRemainder.count-1 do

                        Writeln(TapFile,TapFileRemainder[StringCount]);

                     Close(TapFile);

                  End

               Else

                  Begin

                     windows.messagebox(0,pchar('No Output Tap File Specified 
in Program'),pchar('Error'),MB_OK);

                  End;

               TapFileHeader.Free;

               TapFileJobsList.Free;

               TapFileRemainder.Free;

            End

         Else

            Begin

               windows.messagebox(0,pchar(TapFileName+' Not 
Found'),pchar('Error'),MB_OK);

            End;

      End

   Else

      Begin

         windows.messagebox(0,pchar('No File Name 
Specified'),pchar('Error'),MB_OK);

      End;

End.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to