Solved

Memory I/O Question

Posted on 1998-05-29
8
166 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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

12 Experts available now in Live!

Get 1:1 Help Now