[lazarus] TDBGrid question

Michael Van Canneyt michael.vancanneyt at wisa.be
Mon May 19 05:31:26 EDT 2003




On Mon, 19 May 2003, Jeroen van Iddekinge wrote:

> Hi,
>
> If I simulate what ShiftBuffersUp and ShiftBufferDown do, I think
> thats wrong
>
> First what shiftbuffersup does:
>
> For example
> Buffer: 0123456 (numbers ar original content of buffer before call to shift buffersup )
> procedure is called with the following:
> Offset=2
> Distance=3
> Buffercount=7:
> FirstMove
> move1:
>  "Move(FBuffers[Offset],Temp^,MoveSize);"
>  Temp=234 (temp containts the old buffer 2,3 and 4)
>  buffer=unchanged
>
> move2:
>      Move(FBuffers[Offset+Distance],FBuffers[Offset],
>      (FBufferCount-Distance-Offset)*SizeOf(Pchar));
>                =5                        =2          (2)*sizeof()
>       Temp=unchanged
>        buffer=01563456
> move3:
>    Move(Temp^,FBuffers[FBufferCount-Distance-Offset],MoveSize);
>                          2                             (3)*sizeof
>    temp=unchanged
>    buffer=0123456 <==final.
>
> If i look at the result i find it verry strange...
>
> So far as I understand what procedure  ShiftBuffersDown does, it rotate all the buffers. Thats compleetly different what ShiftBuffersUp does. For
> rotation you don't need an offset parameter, so why does ShiftBuffers have a 'offset' parameter?

The 'offset' is used to make a gap:

[ABCDEFGHIJK]

[ABC DEFGHIJ]

This is needed when doing an insert The insert needs to create a new
buffer at the current location (which is the 'offset'). see line 1043:

   ShiftBuffers(1,FActiveRecord);

But I agree the implementation is messy.
I wanted to have the buffer management in 1 routine;
For clarity it may be needed to split it out in 2 routines, where 1 does
simple rotation (forward/backward) and the second makes the gap for the
new record.

Feel free to have a go at it :-)

Michael.






More information about the Lazarus mailing list