Recent

Author Topic: OpenDocument('Filename') - doesn't ?  (Read 780 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 3466
Re: OpenDocument('Filename') - doesn't ?
« Reply #15 on: July 14, 2026, 08:19:16 am »
@Zvoni  -  My argument about 10 or 1000 lines IS relevant because if the writing of data to the CSVFile is included in the 'Create' Proc then it is no longer a generic Proc.
And that's where i disagree.
But that might be, because i differentiate between "creating" a file, and "writing" to a file.

At the moment of creation of a file (the "rewrite"), the file itself doesn't care, WHAT you are going to write to it.
Thusly implying you can "outsource" any "differing" versions of your Write-Procedure
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 1209
Re: OpenDocument('Filename') - doesn't ?
« Reply #16 on: July 14, 2026, 11:19:59 am »
@Zvoni  -  My argument about 10 or 1000 lines IS relevant because if the writing of data to the CSVFile is included in the 'Create' Proc then it is no longer a generic Proc.
And that's where i disagree.
But that might be, because i differentiate between "creating" a file, and "writing" to a file.

At the moment of creation of a file (the "rewrite"), the file itself doesn't care, WHAT you are going to write to it.
Thusly implying you can "outsource" any "differing" versions of your Write-Procedure

I'm just a little confused now  %)  Though we are surely just discussing 'semantics' .

The sole point of my approach is to separate the 'Creation' from the 'Writing'.

The inclusion of the section :
Code: Pascal  [Select][+][-]
  1. if Result then begin
  2.     /// write your stuff here ///
  3.     system.Close(CSVFile);
  4.   end

in the 'Create' implies (to me) that the work of writing the data to the file happens here.   There could of course be some conditional code in there which points to further external working but I concider that the calling proc should have that locally. All I need the 'Create' proc to do is create (open) the file if possible and flag the user if not.

That (to me) keeps the creation generic so that it can be called from multiple places within the main code with disparate file-names.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Zvoni

  • Hero Member
  • *****
  • Posts: 3466
Re: OpenDocument('Filename') - doesn't ?
« Reply #17 on: July 14, 2026, 12:25:22 pm »
@Zvoni  -  My argument about 10 or 1000 lines IS relevant because if the writing of data to the CSVFile is included in the 'Create' Proc then it is no longer a generic Proc.
And that's where i disagree.
But that might be, because i differentiate between "creating" a file, and "writing" to a file.

At the moment of creation of a file (the "rewrite"), the file itself doesn't care, WHAT you are going to write to it.
Thusly implying you can "outsource" any "differing" versions of your Write-Procedure

I'm just a little confused now  %)  Though we are surely just discussing 'semantics' .

The sole point of my approach is to separate the 'Creation' from the 'Writing'.

The inclusion of the section :
Code: Pascal  [Select][+][-]
  1. if Result then begin
  2.     /// write your stuff here ///
  3.     system.Close(CSVFile);
  4.   end

in the 'Create' implies (to me) that the work of writing the data to the file happens here.   There could of course be some conditional code in there which points to further external working but I concider that the calling proc should have that locally. All I need the 'Create' proc to do is create (open) the file if possible and flag the user if not.

That (to me) keeps the creation generic so that it can be called from multiple places within the main code with disparate file-names.

It's more like this
Code: Pascal  [Select][+][-]
  1. Interface
  2. Procedure MyWriteProcWhichIsinadifferentUnit(Const AFile:File; Data:Pointer);
  3. .......
  4.  
  5. //Somewhere else
  6. if Result then begin
  7.     MyWriteProcWhichIsinadifferentUnit(CSVFile, Pointer(@MyData));
  8.     system.Close(CSVFile);
  9.   end


EDIT: And instead of sending a Pointer, you could even use a "generics" approach
Code: Pascal  [Select][+][-]
  1. Type
  2.    Generic TWriteProc<T>=Procedure(Const AFile:File; Data:T);
  3.  
  4. Var
  5.    MyWriteProcWhichIsinadifferentUnit : specialize TWriteProc<String>;  //Or record-Type or whatever
« Last Edit: July 14, 2026, 12:31:05 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

cdbc

  • Hero Member
  • *****
  • Posts: 2923
    • http://www.cdbc.dk
Re: OpenDocument('Filename') - doesn't ?
« Reply #18 on: July 14, 2026, 12:45:35 pm »
Hi
So all you need from this, is:
Code: Pascal  [Select][+][-]
  1. function CreateCSVFile(Var FN : String;TS : Boolean; out theIOResult: Integer): boolean;    // TS = 'Time-Stamped' | result = success
  2. begin
  3.   Result:= False;  //I like to initialize Result explicitely, though i'm aware, Boolean defaults to 0/False
  4.   if TS then
  5.     FN := FN+TimeStamp+'.CSV'
  6.   else
  7.     FN := FN+'.CSV';
  8.  
  9.   Assign(CSVFile,FN);
  10.   {$I-} rewrite(CSVFile); {$I+}
  11.   theIOResult:= IOResult; { courtesy to user }
  12.   Result:= (theIOResult = 0); { the actual result }
  13. end;
  14.  
-- It opens the file for writing and returns true if successful, while at the same time spitting out the IOResult, or returns false & again the IOResult, for the user to peruse and show appropriate error-message --
I don't think it can be more generic, without actual generics  ;D
Just my 2 cent's worth
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018