Link to home
Start Free TrialLog in
Avatar of nibbler
nibbler

asked on

Memory I/O Question

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
Avatar of JimBob091197
JimBob091197

Hi

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

JB
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

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
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
Avatar of nibbler

ASKER

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...
Avatar of nibbler

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of rickpet
rickpet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial