Recent

Author Topic: Help on saving files  (Read 5674 times)

dixy999

  • Newbie
  • Posts: 3
Help on saving files
« on: March 29, 2011, 10:29:43 pm »
Hi,

I'm having this problem with the TSaveDialog. When i attempt to save data to a binary file it doesnt save the file to the path I browse to in the dialog box. I assume i have to do something like setdir but after trawling google and these forums, i've found nothing of use.
Thanks in advance.

Heres my code:

Code: [Select]
procedure Tpacker_main.btnsaveClick(Sender: TObject);

var
  filename: string;
  openfile: file of Tsave;
  Data:     Tsave;

  ObjectWidthSave: string;
begin
  saveDialog.Filter      := '*.dat';
  saveDialog.DefaultExt  := 'dat';
  saveDialog.FilterIndex := 0;
  SaveDialog.Execute;
  filename := SaveDialog.Filename;
  edit_loadsave.Text := filename;

  Data.ObjectWidthSave    := FloatToStr(ObjectWidth);
  Data.ObjectHeightSave   := FloatToStr(ObjectHeight);
  Data.ObjectDepthSave    := FloatToStr(ObjectDepth);
  Data.ObjectMassSave     := FloatToStr(ObjectMass);
  Data.PackagingThicknessSave := FloatToStr(PackagingThickness);
  Data.PackagingMassSave  := FloatToStr(PackagingMass);
  Data.MaterialThicknessSave := FloatToStr(MaterialThickness);
  Data.PlywoodDensitySave := FloatToStr(PlywoodDensity);

  Assignfile(openfile, filename);
  rewrite(openfile);
  Write(openfile, Data);
  CloseFile(openfile);
end;

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Help on saving files
« Reply #1 on: March 29, 2011, 10:54:11 pm »
I see no problems with TSaveDialog.

Lazarus 0.9.30 r29749 FPC 2.4.2 i386-win32-win32/win64

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Help on saving files
« Reply #2 on: March 29, 2011, 11:03:51 pm »
For me TSaveDialog also works well.

Only note that
Code: [Select]
SaveDialog.Execute is function so your code sould be:
Code: [Select]
if SaveDialog.Execute=true then
  begin
    filename := SaveDialog.Filename;
    edit_loadsave.Text := filename;
    ...

It is for the case that someone cancel SaveDialog.

Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

dixy999

  • Newbie
  • Posts: 3
Re: Help on saving files
« Reply #3 on: March 29, 2011, 11:31:44 pm »
Yeah, TSaveDialog works and saves the file, but not to the path i select in the dialog, it just saves it to the program directory...

P.S.
Thanks Blaazen, i havent fully tested the program yet but this should prevent one more bug.

[EDIT]
Solved

I updated my version of lazarus to 0.9.30  %)
« Last Edit: March 30, 2011, 12:38:36 am by dixy999 »

 

TinyPortal © 2005-2018