PDA

View Full Version : How to write from Pascal's buffer?



Dragoneyes718
10-08-2006, 05:15 AM
Using Turbo Pascal 7.0, I want to copy the data stored in the buffer (not user-defined) into an external file using BlockWrite. What is the correct syntax to do that?

tanffn
10-08-2006, 05:53 AM
its something like this:
var
F: file
dataWriten: Integer;
begin
AssignFile(F, FileName);
BlockWrite( F, buffer, SizeOf(buffer), dataWriten );
// where to, pointer to the data, how much to write, and much had been written
Close(F);
end;

WILL
10-08-2006, 05:54 AM
Wow, you are asking for knowlage on a really obsolite method.

I know this doesn't help with your question, but it'll prehaps explain the difference fromthe old DOS method and the current method. Back in the DOS era when the 640k limitation was still hard to overcome by the OS you had several memory modes 'Real-Time' and 'Protected Mode' (or P-Mode) were the two you had to deal with. Until Borland Pascal 7(released AFTER the TP7 DOS-based compiler) you could only use Real-Time methods. This was a simple matter of calling a GetMem() function and requesting an address in some kind of format like "1F3a:c91a" or something... There was a memory limit though. 1 (or 4) GBs iirc. :?

Anyhow, the current method with Windows and Linux being far beyond the old DOS limitations of that time need only a simple allocation of how much you need and Pointer and a memory size. No dealing with segments and incrimenter, etc... Much simplier, which is why I am recommending a new compiler instead. :)

godbeast
10-08-2006, 09:11 AM
Try Free Pascal. It has excellent syntax compatibility with Turbo Pascal, so you should have no problem at the beggining. Even FP IDE is very simillar to TP [oooops, I guess my reply is a offtopic :wink:]

WILL
10-08-2006, 09:26 AM
Ah... oops. I guess I misread the post. :lol: My humble appologies.

tanffn is basically right. Depends on how you really want to do it. If using Object Pascal instead you could use the TStream Object too as a source for instance.

tanffn
10-08-2006, 10:42 AM
If the kid want to play with an obsolete comelier, let him be :twisted:
Though what WILL and godbeast said is right..

But just so you know I found my self programming with TurboC++ about a month ago, we upgraded an old Mammography system but they didn’t want a radical SW change just HW.. so its still in use today (apparently) and it brought me a lot of nice flashbacks :)

Dragoneyes718
10-08-2006, 03:09 PM
I had made 6 RPG's with that, and just recently found TP7 in my garage, and decided I would start making a compilation of my old games with (slighty) upgraded graphics, and smoother gameplay. Since TP7 is what I found, it's what I'm using.

I was however, interested in FP when I first visited these boards and read a little about it. So I may check it out.

Anyway, thanks for the help! :)

On a side note: I also found a copy of Delphi 4 in my garage, but I'm just not interested in object-oriented programming.

tanffn
10-08-2006, 04:32 PM
I think its against the forum rules to mention M$ compilers :)

Anyway, even if you’re not interested in OOP you can write a console application and keep it all procedural but with many of the FPC benefits.

Dragoneyes718
10-08-2006, 05:39 PM
Hmm. Ok one more question. I managed to write GetImage data from the buffer into a file. I can also read that file later in a different program and use PutImage to display it. This is all working fine.
The problem arises when I create more than one file. For some odd reason, only the most recent file created displays the image it stored correctly. All older files are jarbled when I display them. I'm really confused as to why this is happening.

For instance: I create the file 'square.gfx'; it is a square.
It is fine when used with PutImage later.
Then I create the file 'circle.gfx'; a circle.
Ok now if i read the file and use Putimage with the circle, it displays correctly. However, if I try that with the square, I now just get a bunch of (seemingly) randomly colored pixels.
Any clue what could be causing this?\

Edit: Ok, I may not have actually written the data correctly, or may be reading it in wrong. Because the only way it works is if the buffer hasn't been cleared between programs. I think maybe I only saved the pointer variable to the file. PLEASE HELP! :P