Solved

Memory I/O Question

Posted on 1998-05-29
8
169 Views
Last Modified: 2010-04-06
Hi,

I've got a very BIG problem with delphi 3.0.
I've got a record:

    TheRecord = record
            nr        : integer;
            name : string;            { In real it's a bit bigger, but it's just as example }
    end;

Now I'm writing a procedure that does this:
    procedure do_stuff;
    var f  : TFileStream;
          tr : ^TheRecord;
    begin
        .
        . opens file etc...
        .

        new (tr);        // reserve memory for the TheRecord
         
        { location 1}
        tr^.nr := 5;                        // This goes correctly without Exception

        f.read(tr^, sizeof(TheRecord));

        { location 2}
        tr^.nr := 5;                        // This causes an exception ???

    end;

At location 1, tr  is the address 0AB1026
                        I am able to access it's members
After reading the data, tr STILL POINTS to 0AB1026
                    But now the instruction generates an exception ??

How is this possible ?? Is it a bug in Delphi ??
btw. I've got Delphi 3.0 (build 5.53)

Can somebody help me please,
Thank you  very much in advance,

Rick Blommers
0
Comment
Question by:nibbler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1349158
Hi

Try f.Read(tr, SizeOf(TheRecord)).
(I.e. leave out the ^.

JB
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1349159
I think you need to limit the size of your string...note long strings are now just pointers...

TheRecord = record
            nr        : integer;
            name : string[60];
    end;

Rick Peterson

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1349160
Hi Rickpet

I think that a string declared in a record is automatically treated as a ShortString (length 220, if I remember correctly).

Cheers,
JB
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ssite
ID: 1349161
Hi everyone.

JB : I think you're wrong. Delphi 3 - Longstring unless stated othewise

I would blame this on the borland compiler. I'd bet if you do the classic of :

type
PTheRecord = ^theRecord;

and then declare the other var as PTheRecord, it should work. Let me know
0
 

Author Comment

by:nibbler
ID: 1349162
I've limited the strings, sorry for the 'incorrectness' in the example...
I used a string[50]; or something like that.

I'm also thinking it's the borland compiler, ssite I will let you know when I tried it...
0
 

Author Comment

by:nibbler
ID: 1349163
Hello Rickpet,

I've found the answer, thanks to you. I had one string item
in the record. I limited it size and gone was the exception..

Please send me an answer so I can give you the points !!

Thanks !!!

Rick
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1349164
ssite:  You're right.  I was using different compiler settings for a project.  If Huge Strings is on in Project Options, then uses Long Strings.

Sorry for any confusion,
JB
0
 
LVL 3

Accepted Solution

by:
rickpet earned 50 total points
ID: 1349165
Your welcome...

Rick
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question