Solved

Memory I/O Question

Posted on 1998-05-29
8
165 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

14 Experts available now in Live!

Get 1:1 Help Now