Recent

Author Topic: Delphi 7 handling files  (Read 4446 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Delphi 7 handling files
« Reply #15 on: February 25, 2021, 08:25:22 pm »
maybe the code wasn´t working because it´s an unfixed array
(the write and read you posted)

The code posted by who? My code? It does work, I tested it a little later. If it doesn't work for you, tell us what it is not doing which it should and/or what it is doing that it shouldn't, with as much detail as you can.

And, what do you mean by "unfixed", a dynamic array? It shouldn't matter; except for the need to set its length before accessing its elements (and other, more esoteric things which don't matter here) it works exactly like a normal static array.

The only difference between your code and the same but using a dynamic array is the highlighted line:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. { skipped declarations here }
  6.  
  7. implementation
  8.  
  9. const
  10.   n=30;
  11.  
  12. var
  13.   TheStrings: TStringArray;
  14.  
  15. {$R *.dfm}
  16.  
  17. procedure load(var TheStrings: TStringArray);
  18. var
  19.   i:integer;
  20. begin
  21.   {it starts from zero, but you want it from 1,
  22.    so we add one for it to go from 0 to 30 and
  23.    avoid using TheStrings[0]}
  24.   SetLength(TheStrings, n+1);
  25.   TheStrings[1] := 'First string in this Array';
  26.   {... etc ...}
  27.   TheStrings[30] := 'String number three of this Array';
  28.  
  29.   for i:=1 to n do begin
  30.     showmessage(TheStrings[i]);
  31.   end;
  32. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Mark12345

  • New Member
  • *
  • Posts: 17
Re: Delphi 7 handling files
« Reply #16 on: February 25, 2021, 11:19:56 pm »
Thx I'm gonna try it later(the one you posted with Tfilestream)  so if all of this works the only thing that is missing is the seek
« Last Edit: February 25, 2021, 11:32:01 pm by Iña123 »

Mark12345

  • New Member
  • *
  • Posts: 17
Re: Delphi 7 handling files
« Reply #17 on: March 03, 2021, 09:20:24 pm »
Guys i think i found the solution here, the only thing that remains is the seek , i had to use writebuffer and readbuffer because writeDword and readansistring didn't work in delphi 7
https://stackoverflow.com/questions/46859196/delphi-tfilestream-readbuffer-fails-to-read-string-value-from-file(the guy had an error and people helped him to correct the error, it's in the comments above the solution)
I didn't tried yet but i saw the solution of the person who helped him, (the person who helped him)she put something about char, does that char limit my array to only 255 characters, because i have more than 255 in the array )
« Last Edit: March 03, 2021, 10:05:23 pm by Iña123 »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Delphi 7 handling files
« Reply #18 on: March 03, 2021, 10:19:10 pm »
[...] she put something about char, does that char limit my array to only 255 characters, because i have more than 255 in the array )

No, she's using SizeOf(Char) because Delphi's char type can be one or more bytes, depending on whether you're using by default ANSI or Unicode strings.
« Last Edit: March 03, 2021, 10:21:29 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Delphi 7 handling files
« Reply #19 on: March 03, 2021, 11:50:04 pm »
No, she's using SizeOf(Char) because Delphi's char type can be one or more bytes, depending on whether you're using by default ANSI or Unicode strings.
Not in Delphi 7: that is strictly char...which is byte sized.. I suggest to replace any conflicting code with byte...
D7 can work with unicodestrings, but not like modern Delphi. The question is about D7...
Specialize a type, not a var.

Mark12345

  • New Member
  • *
  • Posts: 17
Re: Delphi 7 handling files
« Reply #20 on: March 04, 2021, 05:18:53 am »
I tried it what they posted with ansistring and Dword and it doesn't start(a lot of errors), because when you put fs. Then it displays a lot of things like write read writebuffer seek readbuffer but it doesn't display ansistring and dword so i think i'm gonna have to use this(the link i posted), so right now the only thing that i don't know how to use is the seek(can you guys help me ?),
 And also Where it says char i have to replace it with byte?

Mark12345

  • New Member
  • *
  • Posts: 17
Re: Delphi 7 handling files
« Reply #21 on: March 08, 2021, 09:38:07 pm »
Guys i replaced the sizeofchar with sizeofbyte and works aswell so the thing that is left is the seek, here it's and example of what i want
https://stackoverflow.com/questions/45548492/delphi-read-file-at-specific-address  (a guy above give him the solution ) so he seek the position sofrombegining and the number he wants to read, the only thing is i don't know if every offset of the array is 1 byte, i think if i put seek($23, sofrombegining) and then fs.readbuffer(TheStrings,1) like he did it would read the whole content of the TheString[23]

Mark12345

  • New Member
  • *
  • Posts: 17
Re: Delphi 7 handling files
« Reply #22 on: April 01, 2021, 11:17:24 pm »
i'm trying to seek and read a file, i think this is what i want
https://stackoverflow.com/questions/45548492/delphi-read-file-at-specific-address
but i don't know what is the program doing because he's reading bytes at a certain offset, i have an array from 1 to 10 of string and i declared  tLength(TheStrings, n+1); ,i want to read all the info that has inside that position let's say  i want to read a random position of thestring[position], random1:=random(10)+1; first i will use seek (random1 minus 1 because it's starts from 0 reading right?sofrombegining or it will starts in 1 because i declared the tlenght from 1 to 10), And then i don't know what to do because he's reading bytes and i don't understand that, i have to know how many bytes has the position that i'm gonna read or what? let's say the random1 got the number 5 so it will have to read the position 4 or the 5 if it starts from 1,
Also i don't know why he put $ in front of the number
And then show it in a memo1(i don't know how)
« Last Edit: April 02, 2021, 05:54:05 am by Iña123 »

Mark12345

  • New Member
  • *
  • Posts: 17
Re: Delphi 7 handling files
« Reply #23 on: April 02, 2021, 06:23:13 am »
When i say read a specific position i mean read an specific line

 

TinyPortal © 2005-2018