3

what i am trying to do right now is to create a scroling credit text using the TMemo component and TTimer

 procedure TAboutBox.Timer1Timer(Sender: TObject);
 begin
 Memo1.ScrollBy(0,-1);
 end;

the Tmemo lines contain the text of the credit, something like :

Thankyou to :
Junifer lamda
Exemple user 2
Coder Monalisa
etc etc

Everything work as expected, i've set the timer.interval to 1ms , the text scroll smoothly but it displays only the 3 first lines then it displays a blank space, unless i click and drag manually using the mouse inside the memo, then it displays some lines then it disappears again when i release.

I tried with both TRichedit and TListBox but the problem persist. How could this be ?

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
  • Yes it is, on win32 TTimer uses a Windows timer, and interval is clipped to USER_TIMER_MINIMUM (0x0000000A) – az01 Jan 01 '12 at 15:52
  • 1
    Do you also consider alternative answers excluding the use of a TMemo/TRichEdit/TlistBox? – menjaraz Jan 01 '12 at 17:26

1 Answers1

4

It seems to me that ScrollBy is not designed to do what you desire. What's more I don't think that TMemo is necessary either.

I'd probably do this with a label and move it on the timer event. Like this:

procedure TScrollingTextForm.FormCreate(Sender: TObject);
begin
  Label1.Caption :=
    'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do '+
    'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad '+
    'minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip '+
    'ex ea commodo consequat. Duis aute irure dolor in reprehenderit in '+
    'voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur '+
    'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '+
    'mollit anim id est laborum.';
  Label1.Top := ClientHeight;
end;

procedure TScrollingTextForm.Timer1Timer(Sender: TObject);
begin
  Label1.Top := Label1.Top - 1;
end;

I found that I needed to make the form double buffered (DoubleBuffered := True) to avoid flicker when scrolling.

LaKraven
  • 5,804
  • 2
  • 23
  • 49
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490