Recent

Author Topic: File IO issues  (Read 1337 times)

dryzone

  • Jr. Member
  • **
  • Posts: 50
Re: File IO issues
« Reply #15 on: March 15, 2025, 03:52:10 am »
@Roland57, Tron

Thank you very much for the examples and helps me greatly.

However, to integrate it in my existing data  read routine is going to take a major rewrite of a perfectly working routine, ... except for my reliance on "Copy" to select data from a string.

I figured out an easy way to get around my problem but need your help.

My program reads from file then isolates a row of data by certain criteria in a large dataset.
The read part of the program is rugged and works great.
The string read from the dataset is e.g.
"                -6.000                 2.000                  30.000                 -12.000                 44.000                      "

Since I keep using dubious methods such as Copy to select e.g. one of the datapoints in the string, what command your suggestion I should use that would ruggedly and reliably read the data above for given index j=1..5 , where the spacing can be variable, but the data is always separated by at least one space.

I know this is a really trivial question someone like me should not ask, but reliability trumps complex questions in my case and my programming field. I clearly invented dubious ways (using Copy) and want to see what the correct way would be in your opinion to read from this supplied string in a reliable fashion.

Thanks


silvercoder70

  • Full Member
  • ***
  • Posts: 164
    • Tim Coates
Re: File IO issues
« Reply #16 on: March 15, 2025, 04:55:37 am »
Try this ...

Code: Pascal  [Select][+][-]
  1. var
  2.   s: string;
  3.   elem: TStringArray;
  4.   i: Integer;
  5.   d: double;
  6. begin
  7.   s := '   5.000       3.000       3.234     234.123  ';
  8.   elem := s.Split(' ', TStringSplitOptions.ExcludeEmpty);
  9.   for i := Low(elem) to High(elem) do
  10.   begin
  11.     d := elem[i].ToDouble;
  12.     writeln(i, '  ', d);
  13.   end;  
  14.  
Explore the beauty of modern Pascal programming with Delphi & Free Pascal - https://www.youtube.com/@silvercoder70

dryzone

  • Jr. Member
  • **
  • Posts: 50
Re: File IO issues
« Reply #17 on: March 15, 2025, 06:26:21 am »
That works great thanks

dryzone

  • Jr. Member
  • **
  • Posts: 50
Re: File IO issues
« Reply #18 on: March 15, 2025, 07:13:42 am »
@SilverCoder70

Is there an equivalent for a string, meaning "dummy" will be a string in the following expression

Code: Pascal  [Select][+][-]
  1. dummy:= elem[j].ToExtended;

Here I have it as an extended, but I want dummy to be a string.
I tried
Code: Pascal  [Select][+][-]
  1. elem[j].ToString;

as ToString is used in several other languages, but it doesnt work in FPK
I get
Error: Illegal qualifier

paweld

  • Hero Member
  • *****
  • Posts: 1356
Re: File IO issues
« Reply #19 on: March 15, 2025, 07:42:14 am »
just
Code: Pascal  [Select][+][-]
  1. string_var := elem[i];
Best regards / Pozdrawiam
paweld

dryzone

  • Jr. Member
  • **
  • Posts: 50
Re: File IO issues
« Reply #20 on: March 15, 2025, 03:58:23 pm »
Thanks to all who responded.

Problem solved.
Works way more reliable now.


 

TinyPortal © 2005-2018