Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SaveFile not SaveDialog 1

Status
Not open for further replies.

CliffClimber

Technical User
Sep 18, 2003
16
US
Hi,
the following code calls the windows save dialog and works just fine, but I wish to specify (no options) where the file is saved. i have read all I can find about SaveFile but can't figure out how to implement it.
Thanks,
Cliff

Code:
procedure TFormMain.ButtonSaveClick(Sender: TObject);
var
   TxtFile: TStringList;
   Txt : String;
begin
    CreatePrintHtml;
    LoadPrintHtml;
//The following names the saved file with the ADDRESS
//as the file name if it exists, if not the file is
//saved using the PARCEL code.
 if MainData.FieldByName('STREETNO').AsString = '' then begin
       SaveDialog1.FileName := MainData.FieldByName('PARCEL').AsString;
 end else begin
     SaveDialog1.FileName := MainData.FieldByName('STREETNO').AsString+' '+
                   MainData.FieldByName('STREETDIR').AsString+' '+
                   MainData.FieldByName('STREETNAME').AsString;
 end;
[endcode]
 
What is the meaning of "I wish to specify (no options) where the file is saved"? Not sure Im getting it right...

1) You not need the user selecting the name (it is selected by the code).

2) You not need the user selecting the directory (this is what Im not sure about).

So, why using a SF dialog if you need nothing from the user? Save the file in code and tell him the path/name with a message window or something like.

buho (A).
 
Hi !
1) I don't need the user selecting the name (it is selected by the code).
2) I don't need the user selecting the directory .(it will be selected by the code)

My problem is that I can't get the the code correct so it will save programatically, without user input.
Thanks

 
Why not? Can you elaborate on the problem?

buho (A).

 
The truth is ..I don't know how to do it or what to use. It seems that SaveFile would work if I new how to implement it.
Currently I am only capable of modifying existing code and I haven't found an example that I can understand yet.
Thanks
 
Ok... dont worry, actually you have not a problem.

The SF is NOT saving the file; it is only allowing the user to set the name/path. The code actually saving the file is somewhere else in the source.

Hunt down a line saying "SaveDialog1.Execute", this is the line opening the dialog. Comment it out.

As you are loading the dialog properties in code, the dialog is ready to be read for the code which use it to save the file.

If the former programmer was not doing something "magic", commenting the line will do the work.

Warning: the code you posted is not defining the directory, do some checks to see if it work as expected(may be you need to set a file/path as SaveDialog1.Name, may be not).

buho (A).

 
Ok I commented out the "Execute" line, but nothing happened when I clicked the Save button because I have not specified where it is to be saved.
So I need to set the directory... (MyPath+'PPL Jan/*.htm')...to a variable and add it into the ...
SaveDialog1.FileName :=( MainData.FieldByName('PARCEL').AsString...?

Code:
procedure TFormMain.ButtonSaveClick(Sender: TObject);
var
   TxtFile: TStringList;
   Txt : String;
begin
    CreatePrintHtml;
    LoadPrintHtml;
//The following names the saved file with the ADDRESS
//as the file name if it exists, if not the file is
//saved using the PARCEL code.
 if MainData.FieldByName('STREETNO').AsString = '' then begin
       SaveDialog1.FileName := MainData.FieldByName('PARCEL').AsString;
 end else begin
     SaveDialog1.FileName := MainData.FieldByName('STREETNO').AsString+' '+
                   MainData.FieldByName('STREETDIR').AsString+' '+
                   MainData.FieldByName('STREETNAME').AsString;
 end;
//    if SaveDialog1.Execute then begin
        if SaveDialog1.FilterIndex = 1 then begin
            if not CopyFile(Pchar(MyPath+'temp/1.htm'), Pchar(SaveDialog1.FileName), False ) then begin
                MessageBeep(MB_ICONHAND);
                MessageDlg(SysErrorMessage(GetLastError), mtError, [mbOk], 0);
            end;
        end;
        if SaveDialog1.FilterIndex = 2 then begin
            TxtFile := TStringList.Create;
            try
               Txt := (WebBrowser1.Document as IHTMLDocument2).body.innerText;
               TxtFile.Add( Txt );
               TxtFile.SaveToFile(SaveDialog1.FileName);
            finally
                TxtFile.Free;
            end;
        end;
    end;
//end;

procedure TFormMain.SaveDialog1TypeChange(Sender: TObject);
begin
    if (SaveDialog1.FilterIndex) = 2 then begin
        MessageBeep(MB_ICONASTERISK);
        MessageDlg('Column formatting of the document will be lost if it is saved as text.', mtInformation, [mbOk], 0);
    end;
end;

procedure TFormMain.LoadPreviewHTMLOnColEnter(Sender: TObject);
    var
         Link : String;
begin
    Link := 'file://'+MyPath+'temp/1.htm';
   ShellExecute(Application.Handle, 'open', PChar(Link), nil, nil, SW_NORMAL);
end;
 
buho,
I got it!!!!
Used the following SaveDialog and it works!
Thanks a bunch!
Cliff


Code:
SaveDialog1.FileName := (MyPath +'PPL Jan/') + MainData.FieldByName('STREETNO').AsString+' '+
                   MainData.FieldByName('STREETDIR').AsString+' '+
                   MainData.FieldByName('STREETNAME').AsString;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top