Solved

Memory I/O Question

Posted on 1998-05-29
8
164 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now